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

xsl:for - Only for existing nodes, how?

Subject: xsl:for - Only for existing nodes, how?
From: "Liron" <magilam@xxxxxxxxxxxxxxxx>
Date: Tue, 21 Feb 2006 17:17:01 +0100
only for each xsl
Hello,

I'm trying to figure out the best way to transform a node-set only if it includes certain nodes, Lets assume I have the following xml structure:

<tree>
  <controls>
     <control>
        <dummy><data>some data</data></dummy>
        <item1><data>some data</data></item1>
        <item2><data>some data</data></item2>
     </control>
     <control>
        <dummy><data>some data</data></dummy>
        <item1><data>some data</data></item1>
        <item2><data>some data</data></item2>
     </control>
  </controls>
</tree>

I want to select the values of item1's data and item2's data so I'm doing this:
<xsl:for-each select="/tree/controls/control">
<xsl:value-of select="item1/data"/>
<xsl:value-of select="item2/data"/>
</xsl:for-each>


This is all fine but my problem begins when there're more "control" nodes with no item1 or item2 children. So if there's one more "control" child (for the example above) which is empty then the for loop will itterate 3 times while I need it to itterate only 2 times for real values. I thought about doing something like:
<xsl:for-each select="/tree/controls/control/item1">
<xsl:value-of select="data"/>
<xsl:value-of select="../item2/data"/>
</xsl:for-each>


But I'm hoping that there's a more celver way to do what I want.

Thank you very much

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.