I am using XSL in Visual Studio 2010. I have the following *XSL*file, and I am attempting to use the tokenize()
function to split a string:
<xsl:stylesheet version='2.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform' >
<xsl:output media-type="text/html; charset=UTF-8" encoding="UTF-8"/>
<xsl:template match='/'>
<html>
<head> </head>
<body>
<ul>
<xsl:apply-templates select="response/result/doc"/>
</ul>
</body>
</html>
</xsl:template>
<xsl:template match="doc">
<xsl:variable name="title" select="str[@name='Title']"/>
<xsl:variable name="features" select="tokenize(str[@name='Desc'],';')"/>
<li>
<xsl:value-of select="$title"/>
<ul>
<xsl:for-each select="$features">
<li>
<xsl:value-of select="."/>
</li>
</xsl:for-each>
</ul>
</li>
</xsl:template>
</xsl:stylesheet>
Note: At this point I am unsure if I am actually using XSLT version 2.0. I think I do because I set it in the first line.
To the above XSL, I get the following error in Visual Studio 2010:
'tokenize()' is an unknown XSLT function.
I have the following input XML file:
<?xml version="1.0" encoding="UTF-8"?>
<response>
<result name="response" numFound="10000" start="0">
<doc>
<str name="Title">Title 1</str>
<str name="Desc">Feature 1; Feature 2; Feature 3;</str>
</doc>
<doc>
<str name="Title">Title 2</str>
<str name="Desc">Feature 1; Feature 2; Feature 3;</str>
</doc>
</result>
</response>
Ideally, I would like to have an output like the HTML file below:
<html>
<head> </head>
<body>
<ul>
<li>Title 1
<ul>
<li>Feature 1</li>
<li>Feature 2</li>
<li>Feature 3</li>
</ul>
</li>
<li>Title 2
<ul>
<li>Feature 1</li>
<li>Feature 2</li>
<li>Feature 3</li>
</ul>
</li>
</ul>
</body>
</html>
How do I tokenize()
or split the string Desc in the XML file? Please ignore whitespace in this i.e. a little extra space before or after in the output file has no meaning since the output is HTML.