[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] xsl:for - Only for existing nodes, how?
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|