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

RE: Finding the current node type

Subject: RE: Finding the current node type
From: "Naschke, Pete" <NaschkePS@xxxxxxxxx>
Date: Mon, 30 Jul 2007 17:58:12 -0500
RE:  Finding the current node type
Could you maybe give me an exact piece of code according to the XML file
Mark included in his original email?

Thanks!


(Sorry to sound like such a beginner (but hey, that's what I am!)...)


-----Original Message-----
From: Kamal Bhatt [mailto:kbhatt@xxxxxxxxx]
Sent: Monday, July 30, 2007 5:55 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re:  Finding the current node type

If I understand what you are trying to do, you could use local-name().
This will give you the name of the node.


Mark Anderson wrote:
> Hi All
>
> I'm trying to figure out a way to determine the "type" of the current
> node in an nodeset.
>
> I have a union of two dissimilar nodesets and I need to number the
> combined set sequentially in my output. I also need to output details
> from each node, but as they are completely different I need to process
> each node type differently based on it's contents.
>
> Here's a silly example
>
> <products>
> 	<speaker>
> 		<woofer>12 inch</woofer>
> 		<rms_power>70 watts</rms_power>
> 		<peak_power>95 watts</peak_power>
> 		<height>40 inches</height>
> 		<width>18 inches</width>
> 		<depth>18 inches</depth>
> 	</speaker>
> 	<laptop>
> 		<disk>80GB</disk>
> 		<screen>15 inch</screen>
> 		<cpu>Intel Core Duo 2.3ghz</cpu>
> 		<weight>5.2lbs</weight>
> 	</laptop>
> 	...
> </products>
>
> So, I need to do something like:
>
> <xsl:for-each select="speaker | laptop">
> 	<!-- Assign a sequential Number -->
> 	Item No: <xsl:value-of select="position()"/> <br />
> 	<!-- Now output item-specific details -->
> 	<xsl:choose>
> 		<xsl:when test="node = speaker">
> 			RMS Power: <xsl:value-of select="rms_power"/>
> <br />
> 			Peak Power: <xsl:value-of select="peak_power"/>
> <br />
> 		</xsl:when>
> 		<xsl:when test="node = laptop">
> 			Disk Drive: <xsl:value-of select="disk"/> <br />
> 			CPU: <xsl:value-of select="cpu"/> <br />
>
> 		</xsl:when>
> 	</xsl:choose>
> </xsl:for-each>
>
> So, what I need to figure out is the test in the when clause to see
> which type of node I'm processing.
>
> I could hack it with something like:
>
> <xsl:when test="count(rms_power) &gt; 0">
> 	<!-- Must be a speaker -->
> 	RMS Power: <xsl:value-of select="rms_power"/>
> 	Peak Power: <xsl:value-of select="peak_power"/>
> </xsl:when>
>
> However, it's messy and I have to find unique child nodes for every
> product.
>
> I'm sure there's a more elegant way
>
> Can anyone help?
>
> TIA
>
> Mark
>
>
>


--
Kamal Bhatt

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Cast Your Vote

We need your help – Vote for DataDirect XML Products!

  • Best SOA or XML site

Winners and finalists announced at SOA World Conference in November.

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-2007 All Rights Reserved.