I saw string-length on this website http://www.xsltfunctions.com/xsl/fn_string-length.html I think it's the xslt 2.0 syntax.
though, in xslt 1.0, i tried this:
<xsl:template match="/">
<xsl:value-of select="string-length(())" />
</xsl:template>
and i got an error. is there any function that i can use to convert () and pass it to string-length so that I can get 0?
The XPath 1.0 string-length()
takes a single string argument. Anything that is not a string will be converted to a string for you. An empty set of parentheses can't be converted, and there are no sequences in 1.0. To get 0
, you can feed the empty string:
<xsl:template match="/">
<xsl:value-of select="string-length('')" />
</xsl:template>
to get something meaningful, you can feed a node-set, for example:
<xsl:template match="/">
<xsl:value-of select="string-length(some/xpath)" />
</xsl:template>
The first node in the node-set would be converted to a string and passed to the function.
A little more info: If you don't pass any argument to string-length() it will evaluate the current context node.
Note that the xpath passed as argument is relative to the current context in the xpath expression
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With