[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
[Recent Entries]
[Reply To This Message]
Re: xslt 1, node sets in variables
Subject: Re: xslt 1, node sets in variables
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Fri, 31 Jul 2009 16:48:10 -0400
|
Joelle,
Where you have
<xsl:value-of select="count(exsl:node-set($projects))"/>
you are counting the node set you get back from calling the extension
function with the variable $projects as its argument.
But nowhere in your code do you declare what $projects is. So this is
probably giving you an error.
Note in particular that $projects will not be whatever results from
matching the 'projects' element in your input with the template where
this appears.
You need to bind the variable and then process it. So, something like:
<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
At 04:39 PM 7/31/2009, you wrote:
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
======================================================================
|
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format
RSS 2.0 |
|
Atom 0.3 |
|
|