xml - The return type of <xsl:variable name="pubDate" select="publicationDate" />, a node-set or a string? -
i new xsl , using version 1.0
here xml source
<?xml version="1.0"?> <catalog> <cd> <title>empire burlesque</title> <artist>bob dylan</artist> <company>columbia</company> <publicationdate>03/31/1985</publicationdate> </cd> </catalog>
from above xml content, set varialbe in xsl code by
<xsl:variable name="pubdate" select="//publicationdate" />
i thought variable 'pubdate' should contain node-set because of '//publicationdate' realized possible apply string function such substring($pubdate, 1, 4) hints 'pubdate' string.
is automatic type cast or else?
in xslt 1.0 $pubdate
node-set. if reference in function expects string value parameter, use string value of first node in node set. say, text value of node , descendant nodes. if first node looked this:
<publicationdate><mm>03</mm><dd>31</dd><yy>1985</yy></publicationdate>
then substring($pubdate, 1, 4)
still output 0331
.
things different in xslt 2.0 though. contain sequence, if tried same substring expression error "a sequence of more 1 item not allowed first argument of substring()"
edit: now, if had done this...
<xsl:variable name="pubdate"> <xsl:copy-of select="//publicationdate" /> </xsl:variable>
then $pubdate
contains "result tree fragment". can still use in string function, use string value of entire result tree fragment in case.
Comments
Post a Comment