XSLT - make xsl:analyze-string return string instead of sequence of strings?
Posted
by
tohuwawohu
on Stack Overflow
See other posts from Stack Overflow
or by tohuwawohu
Published on 2012-03-22T10:14:03Z
Indexed on
2012/03/22
11:29 UTC
Read the original article
Hit count: 313
xslt-2.0
Is it possible to make xsl:analyze-string
return one string instead of a sequence of strings?
Background: I'd like to use xsl:analyze-string
in a xsl:function
that should encapsulate the pattern matching. Ideally, the function should return an xs:string
to be used as sort criteria in an xsl:sort
element.
At the moment, i have to apply string-join() on every result of the function call since xsl:analyze-string
returns a sequence of strings, and xsl:sort
doesn't accept such a sequence as sort criteria. See line 24 of the stylesheet:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:my="www.my-personal-namespa.ce"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:output indent="yes" method="xml" />
<xsl:function name="my:sortierung" >
<xsl:param name="inputstring" as="xs:string"/>
<xsl:analyze-string select="$inputstring" regex="[0-9]+">
<xsl:matching-substring>
<xsl:value-of select="format-number(number(.), '00000')" />
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:value-of select="." />
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:function>
<xsl:template match="/input">
<result>
<xsl:apply-templates select="value" >
<xsl:sort select="string-join((my:sortierung(.)), ' ')" />
</xsl:apply-templates>
</result>
</xsl:template>
<xsl:template match="value">
<xsl:copy-of select="." />
</xsl:template>
</xsl:stylesheet>
with this input:
<?xml version="1.0" encoding="UTF-8"?>
<input>
<value>A 1 b 120</value>
<value>A 1 b 1</value>
<value>A 1 b 2</value>
<value>A 1 b 1a</value>
</input>
In my example, is there a way to modify the xsl:function to return a xs:string instead of a sequence?
© Stack Overflow or respective owner