|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] xpath index-of function using xslt 3.0
Hi all,
I've just been trying to implement XPath 3.1 function 'index-of', with
XSLT 3.0 code using xsl:iterate instruction, and came up with following XSL
stylesheet,
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:fn0="http://fn0"
exclude-result-prefixes="#all"
version="3.0">
<xsl:output method="xml" indent="yes"/>
<xsl:variable name="var1" select="('abc1', 'abc2', 'abc1', 'abc5',
'abc4')" as="xs:string*"/>
<xsl:template match="/">
<result>
<xsl:for-each select="('abc1', 'abc4')">
<index srch="{.}"><xsl:value-of
select="fn0:indexOf($var1, .)"/></index>
</xsl:for-each>
</result>
</xsl:template>
<xsl:function name="fn0:indexOf" as="xs:integer*">
<xsl:param name="strList" as="xs:string*"/>
<xsl:param name="srch1" as="xs:string"/>
<xsl:iterate select="$strList">
<xsl:param name="result" select="()" as="xs:integer*"/>
<xsl:on-completion>
<xsl:sequence select="$result"/>
</xsl:on-completion>
<xsl:if test=". = $srch1">
<xsl:next-iteration>
<xsl:with-param name="result" select="($result,
position())"/>
</xsl:next-iteration>
</xsl:if>
</xsl:iterate>
</xsl:function>
</xsl:stylesheet>
The above cited stylesheet, produces following XSL transformation result,
<?xml version="1.0" encoding="UTF-8"?><result>
<index srch="abc1">1 3</index>
<index srch="abc4">5</index>
</result>
This works fine with both Saxon-HE 12.5 XSLT 3.0 processor and Apache
Xalan's XSLT 3.0 development code.
Thought that, I should share this XSL stylesheet example, for comments from
anyone interested within this XSL list.
--
Regards,
Mukul Gandhi
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








