Subject: Re: [xsl] A function that tokenizes a string, wrapping each token in start-tag , end-tag pairs? From: "Martin Honnen martin.honnen@xxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Thu, 21 Apr 2016 12:29:37 -0000 |
I've implemented the function, see below. It works fine, but I want to know
if it can be improved. Is there a way to write the function more idiomatic? Shorter? Generalized to be more widely useful? /Roger
codepoints-to-string($line-delimiter))" as="xs:string*" />
<!-- Create an element for each non-empty token in $line. $line is tokenized using the sequence of symbols denoted by $line-delimiter. For the token at position i, name the element using the string in headers[$i] --> <xsl:function name="f:line" as="element()*"> <xsl:param name="line" as="xs:string" /> <xsl:param name="line-delimiter" as="xs:integer+" /> <xsl:param name="headers" as="xs:string+" />
<xsl:variable name="tokens" select="tokenize($line,
<xsl:variable name="len" select="count($tokens)" as="xs:integer"/>
as="xs:integer" /><xsl:for-each select="1 to $len"> <xsl:variable name="index" select="xs:integer(.)"
<xsl:variable name="value" select="$tokens[position() eq$index]" as="xs:string" />
<xsl:choose> <xsl:when test="$value eq ''"/> <xsl:otherwise> <xsl:element name="{$headers[position() eq $index]}"> <xsl:sequence select="$value"/> </xsl:element> </xsl:otherwise> </xsl:choose> </xsl:for-each>
</xsl:function>
<xsl:for-each select="tokenize($line, codepoints-to-string($line-delimiter))"> <xsl:if test=". ne ''"> <xsl:variable name="pos" select="position()"/> <xsl:element name="{$headers[$pos]}"> <xsl:value-of select="."/> ?
--- Diese E-Mail wurde von Avast Antivirus-Software auf Viren gepr|ft. https://www.avast.com/antivirus
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] A function that tokenizes a s, Costello, Roger L. c | Thread | Re: [xsl] A function that tokenizes, Michael Kay mike@xxx |
[xsl] A function that tokenizes a s, Costello, Roger L. c | Date | Re: [xsl] A function that tokenizes, Costello, Roger L. c |
Month |