我是 XSLT 2.0 的新手。我对用户定义的函数 ( <xsl:function) 很感兴趣。特别是,我想使用 UDF 使代码更具模块化和可读性。
我有这个 xsl:
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet
   version="2.0"
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
    <xsl:variable name="stopwords"
        select="document('stopwords.xml')//w/string()"/>
             <wordcount>
                <xsl:for-each-group group-by="." select="
                    for $w in //text()/tokenize(., '\W+')[not(.=$stopwords)] return $w">
                    <xsl:sort select="count(current-group())" order="descending"/>            
                    <word word="{current-grouping-key()}" frequency="{count(current-group())}"/>
                </xsl:for-each-group>
             </wordcount>
</xsl:template>
</xsl:stylesheet>
可能想要添加更多条件测试(例如,排除数字), 
for $w in //text()/tokenize(., '\W+')[not(.=$stopwords)] 
但代码会变得混乱。
如果我使它更复杂,UDF 是否是整理该部分代码的选项。这样做是个好习惯吗?