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

Re: Filtering nodes

Subject: Re: Filtering nodes
From: Joerg Heinicke <joerg.heinicke@xxxxxx>
Date: Tue, 14 May 2002 01:22:33 +0200
Re:  Filtering nodes
<xsl:template match="Record">
  <xsl:copy>
    <xsl:copy-of select="@*"/>
    <xsl:apply-templates/>
  </xsl:copy>
</xsl:template>

<!-- empty records -->
<xsl:template match="Record[not(@*)]">
  <xsl:apply-templates/>
</xsl:template>

<!-- records with leaves -->
<xsl:template match="Record[Leaf]">
  <Leaf Name="{@Name}"/>
</xsl:template>

Regards,

Joerg


Suresh Babu schrieb:
Hello group,

I have a simple XML like

 <Root>
     <Record Name="R1">
	<Record Name="L1">
		<Leaf Name="text"/>
	</Record>
	<Record>
		<Record Name="L2">
			<Leaf Name="text"/>
		</Record>
	</Record>
	<Record Name="R2">
		<Record>
			<Record>
				<Record>
					<Record Name="LL1">
						<Leaf Name="text"/>
					</Record>
					<Record Name="LL2">
						<Leaf Name="text"/>
					</Record>
				</Record>
			</Record>
		</Record>
	</Record>
 </Root>

To transform it to a simple structure like
<Record Name="R1">
	<Leaf Name="L1"/>
	<Leaf Name="L2"/>
	<Record Name="R2>
		<Leaf Name="LL1"/>
		<Leaf Name="LL2"/>
	</Record>
</Record>

Could any one suggest ways to filter the dummy record nodes under R1 and R2
and display the Leaf nodes under R1 and R2.

For displaying the field nodes under a specific record I used the keys
function to select the "Record" elements with a "Leaf" element and having
attribute "Name" value "text" as follows:
 <xsl:key name="leaf-nodes" match="Record" use="Leaf/@Name"/>

This is fine for R2 but fails for R1 in which case it is diplaying all the
fields in R2 also.

Could some correct the keys expression/suggest a better way for doing this.

Thanks and regards,
Suresh


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.