I'm just starting XSLT and I try to use the str:tokenize() template in XSLT 1.0. I checked on: http://www.exslt.org/str/functions/tokenize/index.html
But I can't get the expected result.
This is the code:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:exsl="http://exslt.org/common"
xmlns:str="http://exslt.org/strings"
exclude-result-prefixes="str">
<xsl:output method="xml"/>
<xsl:template match="/">
<xsl:variable name="var" select="John.Wayne"/>
<root>
<xsl:for-each select="str:tokenize($var,'.')">
<element>
<xsl:value-of select="."/>
</element>
</xsl:for-each>
</root>
</xsl:template>
</xsl:stylesheet>
My expected output should be:
<root>
<element>John</element>
<element>Wayne</element>
</root>
Any help appreciated. Thanks in advance! Oh, by the way, my output is:
<?xml version="1.0"?>
<root/>
(I'm using xsltproc)
The problem is not with tokenize, but with how you set the variable
This is looking for an element named
John.Wayne
. I guess you really want to use a string literal here...Try this!
The line
is assigning to
var
the result of the evaluation of the XPathJohn.Wayne
.To assign to
var
the string valueJohn.Wayne
you have to surround it with single quotes: