xsl-list
[Top] [All Lists]

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

2009-07-31 17:12:55
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[(_at_)active!=0]"/>
               </xsl:when>
               <xsl:when test="$active_filter = 'archived'">
                   <xsl:copy-of select="project[(_at_)active=0]"/>
               </xsl:when>
               <xsl:when test="$active_filter = 'new'">
                   <xsl:copy-of select="project[(_at_)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[(_at_)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

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>