This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: Returning A Tree


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@iclway.co.uk>
Subject: RE: [xsl] 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]