Subject: Re: [xsl] xslt 1, node sets in variables From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx> Date: Fri, 31 Jul 2009 16:48:10 -0400 |
<!-- 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
From my research on the web, it seems like I should be able to do this, but I can't seem to make it work. How can I get a node set into a variable so that I can do processing on it before it goes to the new template? (or some other way to get the same functionality.
I'm using xslt 1, using libxml via php.
Any help or pointers would be appreciated.
My xml varies (sometimes the projects are nested deeper, etc) but the general point is
<projects>
<project @active="1" @new="1">stuff</project>
<project @active="2" @new="0">stuff</project>
<project @active="0" @new="0">stuff</project>
etc.
</projects>
The error I'm getting is: **public_project_list_display.xsl line 76 element apply-templates The 'select' expression did not evaluate to a node set. ** The stylesheet is
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exsl="http://exslt.org/common" extension-element-prefixes="exsl">
<xsl:template match="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:value-of select="count(exsl:node-set($projects))"/> <xsl:value-of select="name(exsl:node-set($projects)[1])"/>
<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>
<xsl:template name="not_pagenated"> <xsl:param name="projects"/>
<ul class="list-menu results"> <xsl:apply-templates select="$projects"> <-- line 76 <xsl:sort select="@sort_key"/> </xsl:apply-templates> </ul> </xsl:template>
====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] xslt 1, node sets in variable, Joelle Tegwen | Thread | Re: [xsl] xslt 1, node sets in vari, Joelle Tegwen |
[xsl] xslt 1, node sets in variable, Joelle Tegwen | Date | Re: [xsl] xslt 1, node sets in vari, Joelle Tegwen |
Month |