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

RE: Returning A Tree

Subject: RE: Returning A Tree
From: Darren Hayduk <dhayduk@xxxxxxxxxxxxxxx>
Date: Wed, 5 Sep 2001 13:25:08 -0400
hayduk
OK, here is an example. 

XML:
<top>
    <B>B1</B>
    <A>A1</A>
    <A>A2</A>
    <B>B2</B>
    <B>B3</B>
    <A>A3</A>
    <A>A4</A>
    <B>B4</B>
</top>

XSL:
<xsl:template name="selectNodes">
  <xsl:param name="doWhat"/>
  <xsl:choose>
     <xsl:when test="$doWhat='GiveMeA'">
        <xsl:for-each select="//A">
           <xsl:value-of select="."/>
        </xsl:for-each>
     </xsl:when>
     <xsl:when test="$doWhat='GiveMeB'">
        <xsl:copy-of select="//B"/>
     </xsl:when>
  </xsl:choose>
</xsl:template>

<xsl:template match="/">
  <xsl:text>The A nodes: </xsl:text>
  <xsl:variable name="A">
     <xsl:call-template name="selectNodes">
        <xsl:with-param select="'GiveMeA'" name="doWhat"/>
     </xsl:call-template>
  </xsl:variable>
  <xsl:for-each select="$A">
     <xsl:value-of select="."/>
     <xsl:if test="not(position()=last())">
        <xsl:text>,</xsl:text>
     </xsl:if>
  </xsl:for-each>
  <xsl:text> and the count is </xsl:text>
  <xsl:value-of select="count($A)"/>

  <xsl:text>&#10;The B nodes: </xsl:text>
  <xsl:variable name="B">
     <xsl:call-template name="selectNodes">
        <xsl:with-param select="'GiveMeB'" name="doWhat"/>
     </xsl:call-template>
  </xsl:variable>
  <xsl:for-each select="$B">
     <xsl:value-of select="."/>
     <xsl:if test="not(position()=last())">
        <xsl:text>,</xsl:text>
     </xsl:if>
  </xsl:for-each>
  <xsl:text> and the count is </xsl:text>
  <xsl:value-of select="count($B)"/>
</xsl:template>

Why is the output the same (my understanding is that GiveMeA should give me
a text node, but I thought that GiveMeB would be a node set)? I want the
output to be:

"The A nodes: A1,A2,A3,A4 and the count is 4"
etc.

Thanks,
Darren


-----Original Message-----
Date: Wed, 5 Sep 2001 08:48:39 +0100
From: "Michael Kay" <mhkay@xxxxxxxxxxxx>
Subject: RE:  Returning a Tree

> I'm trying to construct a template (call-template) that will
> return a node set, and I can't figure out how to do it.
>
Named templates don't return anything, they write new nodes either to the
final result tree or to a "result tree fragment".

You need to explain the problem you are trying to solve...

Mike Kay

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.