Subject: Re: [string to node]
From: Syd Bauman <Syd_Bauman@xxxxxxxxx>
Date: Sun, 21 Feb 2010 17:35:09 -0500
|
This post is full of self-help realism, and completely lacks
explanation. That's for a reason -- I'm not near a reference work to
double check on the reason. :-)
> Specifically in XALAN-C processor.
I also don't have ready access to the Xalan-C processor, but using
`xsltproc`, I found it instructive to put content into the <dd>
elements and examine the output of the following two stylesheets. The
first is just like yours (except the do-nothing conditional is
removed), and the second is the same but with apply-templates instead
of value-of.
Input
-----
<?xml version="1.0" encoding="UTF-8"?>
<a>
<dd>one</dd>
<dd>two</dd>
<dd>three</dd>
</a>
Test1
-----
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="UTF-8"/>
<xsl:template match="/">
<xsl:variable name="a">
<xsl:value-of select="//dd"/>
</xsl:variable>
<xsl:value-of select="count($a)"/>
<xsl:text>: "</xsl:text>
<xsl:value-of select="$a"/>
<xsl:text>"</xsl:text>
</xsl:template>
</xsl:stylesheet>
Test2
-----
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="UTF-8"/>
<xsl:template match="/">
<xsl:variable name="a">
<xsl:apply-templates select="//dd"/>
</xsl:variable>
<xsl:value-of select="count($a)"/>
<xsl:text>: "</xsl:text>
<xsl:value-of select="$a"/>
<xsl:text>"</xsl:text>
</xsl:template>
</xsl:stylesheet>
Output1
-------
<?xml version="1.0" encoding="UTF-8"?>
1: "one"
Output2
-------
<?xml version="1.0" encoding="UTF-8"?>
1: "onetwothree"
In both cases it seems as though $a contains only 1 thing, a string.
(You can test that it is not a node set by using $a in the select= of
a for-each -- you should get a runtime error, since it is a string.)
> So, my objective is to get the count() function to count the number of
> 'dd' elements.
>
> test.xsl
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> <xsl:output method="xml" encoding="UTF-8"/>
>
> <xsl:template match="/">
> <xsl:variable name="a">
> <xsl:choose>
> <xsl:when test="1=1">
> <xsl:value-of select="//dd"/>
> </xsl:when>
> </xsl:choose>
> </xsl:variable>
> <xsl:value-of select="count($a)"/>
> </xsl:template>
> </xsl:stylesheet>
>
>
> test.xml
>
> <a>
> <dd/>
> <dd/>
> <dd/>
> </a>
|