This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: Multiple instances of the same nodeset - is this possible.
- From: John Aschenbrenner <jaschenbrenner at ignitionmts dot com>
- To: "'xsl-list at lists dot mulberrytech dot com'" <xsl-list at lists dot mulberrytech dot com>
- Date: Mon, 5 Aug 2002 11:43:40 -0700
- Subject: RE: [xsl] Multiple instances of the same nodeset - is this possible.
- Reply-to: xsl-list at lists dot mulberrytech dot com
Thanks Mike, the idea of using a key is new to me but appears to be an
efficient method. I am going to implement this instead of the recursive
solution.
-----Original Message-----
From: Mike Brown [mailto:mike@skew.org]
Sent: Sunday, August 04, 2002 11:46 PM
To: xsl-list@lists.mulberrytech.com
Subject: Re: [xsl] 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
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list