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

Re: Create a list of values from multiple elements

Subject: Re: Create a list of values from multiple elements
From: "Andrew Welch" <andrew.j.welch@xxxxxxxxx>
Date: Wed, 4 Jul 2007 10:33:15 +0100
Re:  Create a list of values from multiple elements
On 7/4/07, Michael Eberhard <michael_eberhard@xxxxxx> wrote:
Hi,

I want to create a list of IDs while transforming one part of the XML document, as the transformation of the second part is based on the IDs chosen before.

The input XML document looks like this:

<MainElement id="0" val="10"/>
<MainElement id="1" val="20"/>
<MainElement id="2" val="30"/>
<ExtElement mid="0" ... />
<ExtElement mid="0" ... />
<ExtElement mid="1" ... />
<ExtElement mid="2" ... />

The style sheet has a parameter, which allows to specify the desired maximum value. If the input parameter is a value of 20, the output should look like this:

<MainElement id="0" val="10"/>
<MainElement id="1" val="20"/>
<ExtElement mid="0" ... />
<ExtElement mid="0" ... />
<ExtElement mid="1" ... />

My question is now, how can I store the IDs of the MainElements while processing them in order to have the IDs available when processing the ExtElements (using XSLT 1.0).


Use the identity transform with a no-op template for each of
conditions where you don't want to copy the input to the result.  The
tricky part of looking up the <MainElement> from the <ExtElement> can
be done using a key:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:param name="max" select="'20'"/>

<xsl:key name="mainElem-by-id" match="MainElement" use="@id"/>

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

<xsl:template match="MainElement[@val > $max]"/>

<xsl:template match="ExtElement[key('mainElem-by-id', @mid)/@val > $max]"/>

</xsl:stylesheet>

generates:

<MainElement id="0" val="10"/>
<MainElement id="1" val="20"/>

<ExtElement mid="0"/>
<ExtElement mid="0"/>
<ExtElement mid="1"/>

cheers
andrew
--
http://andrewjwelch.com

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.