[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: mixing recursive template calls and for-each

Subject: Re: mixing recursive template calls and for-each
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Thu, 4 Jul 2002 12:37:46 +0100
mixing items list
Hi Yvan,

As Mike said, you'll probably find this easier to manage if you have
separate templates for different elements. The basic template that you
need is an identity template that copies everything from the source to
the result:

<xsl:template match="node()|@*">
  <xsl:copy>
    <xsl:apply-templates select="node()|@*" />
  </xsl:copy>
</xsl:template>

Then you need to handle the elements in your place namespace
differently, so you need separate templates for them. When you find a
place:list-of element, you want to locate the elements named by its
'node' attribute within the source element child of the place:list-of
element, in order to create the list:

<xsl:template match="place:list-of">
  <xsl:variable name="element" select="@node" />
  <xsl:variable name="items"
                select="source//*[name() = $element]" />
  ...
</xsl:template>

Then you want to iterate over the items in that list, using the second
element child of the place:list-of element as a template. To do that,
you should apply templates to that element, passing the item element
(in this case the 'workitem' element) as a parameter:

<xsl:template match="place:list-of">
  <xsl:variable name="element" select="@node" />
  <xsl:variable name="items"
                select="source//*[name() = $element]" />
  <xsl:variable name="template"
                select="*[2]" />
  <xsl:for-each select="$items">
    <xsl:apply-templates select="$template">
      <xsl:with-param name="item" select="." />
    </xsl:apply-templates>
  </xsl:for-each>
</xsl:template>

The place:value-of element needs to handle the $item passed as a
parameter in order to get the value of the child element named by its
name attribute:

<xsl:template match="place:value-of">
  <xsl:param name="item" select="/.." />
  <xsl:variable name="element" select="@name" />
  <xsl:value-of select="$item/*[name() = $element]" />
</xsl:template>

Finally, to make sure that the place:value-of elements actually get
the $item parameter set, you need to make sure that the $item
parameter is passed through the templates as you process the elements,
by amending the identity template as follows:

<xsl:template match="node()|@*">
  <xsl:param name="item" select="/.." />
  <xsl:copy>
    <xsl:apply-templates select="node()|@*">
      <xsl:with-param name="item" select="$item" />
    </xsl:apply-templates>
  </xsl:copy>
</xsl:template>

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.