XSLT-Benutzer-Definierte Funktion

Ich bin neu in XSLT 2.0. Ich bin fasziniert von Benutzer-Definierten Funktionen ( <xsl:function ). Insbesondere, ich möchte eine UDF benutzen um den code modularer und lesbarer.

Habe ich dieses 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>

Können hinzufügen möchten weitere Bedingung testen (beispielsweise ausschließen Ziffern), um die
for $w in //text()/tokenize(., '\W+')[not(.=$stopwords)]
aber der code würde sich chaotisch.

Ist eine UDF eine option, um aufzuräumen, code-Abschnitt, der, wenn ich es komplexer. Ist es gute Praxis, dies zu tun?

Nicht unterstützt XSLT 1.0, 2.0: w3.org/TR/xslt20/#stylesheet-functions

InformationsquelleAutor Paulb | 2013-08-17

Schreibe einen Kommentar