[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: [string to node]

Subject: Re: [string to node]
From: Syd Bauman <Syd_Bauman@xxxxxxxxx>
Date: Sun, 21 Feb 2010 17:35:09 -0500
Re:  [string to node]
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>

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.