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

Re: Multiple instances of the same nodeset - is this p

Subject: Re: Multiple instances of the same nodeset - is this possible.
From: Mike Brown <mike@xxxxxxxx>
Date: Mon, 5 Aug 2002 00:46:14 -0600 (MDT)
Re:  Multiple instances of the same nodeset - is this p
John Aschenbrenner wrote:
> I often find myself in a situation where I would like to traverse a nodeset
> multiple times simultaneously in a document.

Well, in general, that's what template modes are for.
For example, at some point you use 

  <xsl:apply-templates select="/path/to/some/nodes"/>

when you want normal processing, and 

  <xsl:apply-templates select="/path/to/some/nodes" mode="foo"/>

when you want to process the same nodes another way,
using a template like:

  <xsl:template match="nodes" mode="foo">
    ...
  </xsl:template>

It's a good way to produce multiple views of the same data. Your example would
not benefit from this, though. You can reuse $GetMessagesSet1 because the set
does not change. There's no need to have identical sets. That is, your inner
for-each could look like this (untested):

<xsl:for-each select="$GetMessagesSet1[@MessageID=$MessageID]">
  <xsl:value-of select="@Message"/>
</xsl:for-each>

> I have since solved my problem by using a recursive template

Probably not the best solution.

You might look into using xsl:key and key() to get the Message attributes
more efficiently. For example, run this against your sample data to get
the general idea:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:output method="html" indent="yes"/>

  <!--
     for our purposes,
     key('msg',foo) is essentially the same as //row[@MessageID=foo]
  -->
  <xsl:key name="msg" match="row" use="@MessageID" />

  <xsl:template match="/">
    <table>
      <xsl:for-each select="/root/row[@FieldName='ListOfMessages' and @IsNewline='True']">
        <tr>
          <td>___</td>
          <td>
            <xsl:for-each select="key('msg',@MessageID)">
              <xsl:value-of select="@Message"/>
              <br/>
            </xsl:for-each>
          </td>
        </tr>
      </xsl:for-each>
    </table>
  </xsl:template>

</xsl:stylesheet>

   - Mike
____________________________________________________________________________
  mike j. brown                   |  xml/xslt: http://skew.org/xml/
  denver/boulder, colorado, usa   |  resume: http://skew.org/~mike/resume/

 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.