Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 26th, 2007, 09:54 PM
Authorized User
 
Join Date: Jun 2006
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default Creating a template to generate a node set

Hi there,


I have been using templates where I pass in a node set and the template returns a single value.

Just wondering if it is possible to pass a parameter which contains a node set to a template. And this template does some processing to this node set and generates another node set.

for eg. my node set is such
<parent>
  <name>john</name>
  <amount>50</amount>
<parent>

so I call the template in my xslt
<xsl:variable name="result_node">
  <xsl:call-template name="process_parent">
    <xsl:param name="myNode" select=parent[1]/>
  </xsl:call-template>
</xsl:variable>

the result_node should hopefully be
<person>
  <name>john</name>
  <balance>positive</balance>
</person>

thanks


 
Old July 27th, 2007, 02:51 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Your "node set" seems actually to be a tree rooted at a single node (the children don't count, they come with it automatically). So the simplest way to "pass it to a template" is to call apply-templates on it.

You actually seem to be doing a standard transformation on this tree, so you want an identity template that copies things unchanged:

<xsl:template match="*">
  <xsl:copy>
    <xsl:apply-templates/>
  </xsl:copy>
</xsl:template>

and another one that changes amount into balance:

<xsl:template match="amount[. &gt; 0]">
  <balance>positive</balance>
</xsl:template>

<xsl:template match="amount[. = 0]">
  <balance>zero</balance>
</xsl:template>

<xsl:template match="amount[. &lt; 0]">
  <balance>overdrawn</balance>
</xsl:template>

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
XPath: set operation with a disjoint node set rich_unger XSLT 7 May 6th, 2008 09:24 AM
Auto generate get and set methods jdang67 .NET Framework 2.0 10 January 16th, 2008 08:20 AM
Filtering out from a node set anothervbaddict XSLT 1 May 22nd, 2007 08:42 AM
node-set function Bernardo Pacheco XSLT 2 June 19th, 2006 10:45 AM
Counting node-set children in template rufustfirefly XSLT 2 May 3rd, 2004 08:48 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.