This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Multiple instances of the same nodeset - is this possible.


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]