Re: [xsl] xslt 1, node sets in variables

Subject: Re: [xsl] xslt 1, node sets in variables
From: Joelle Tegwen <tegwe002@xxxxxxx>
Date: Fri, 31 Jul 2009 16:13:04 -0500
Sorry, I had been making multiple changes to the code and didn't get it rolled back far enough.

When I do what you suggested, it doesn't generate any errors, but I still don't get the result as a node-set. The copy-of statement dumps the xml of the tree to the output. Also, count(exsl:node-set($projects)) returns 1 (It should return 26 when there is no filter).

<xsl:template match="projects">
<xsl:variable name="projects">
<xsl:choose>
<xsl:when test="$active_filter = 'active'">
<xsl:copy-of select="project[@active!=0]"/>
</xsl:when>
<xsl:when test="$active_filter = 'archived'">
<xsl:copy-of select="project[@active=0]"/>
</xsl:when>
<xsl:when test="$active_filter = 'new'">
<xsl:copy-of select="project[@new=1]"/>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="project"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:copy-of select="$projects"/>
<xsl:choose>
<xsl:when test="count(exsl:node-set($projects))>10">
<xsl:call-template name="pagenated">
<xsl:with-param name="projects" select="exsl:node-set($projects)"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="not_pagenated">
<xsl:with-param name="projects" select="exsl:node-set($projects)"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>


Thanks for your help.
J


Wendell Piez wrote:

<xsl:template match="projects">


  <!-- first, bind the variable -->
  <xsl:variable name="projects">
    <xsl:choose>
      <xsl:when test="$active_filter = 'active'">
        <xsl:copy-of select="project[@active!=0]"/>
      </xsl:when>
    (... etc ...)
  </xsl:variable>

  <!-- now, you want to copy it to the result of this template -->
  <xsl:copy-of select="$projects"/>

  <!-- next, all the other stuff using the variable -->
  <xsl:value-of select="count(exsl:node-set($projects))"/>
    (... etc ...)
</xsl:template>

I hope that helps,
Wendell

Current Thread