tags:

views:

396

answers:

1

I saw string-length on this website http://www.xsltfunctions.com/xsl/fn%5Fstring-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?

+1  A: 

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.

Tomalak