XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Shailendra GodboleSubject: Help required on Multiple child processings
Author: Shailendra Godbole
Date: 28 Dec 2005 02:10 PM
Originally Posted: 28 Dec 2005 02:11 PM
Hi,

I have following XML and the expected result is written down please help
regards
Shailen

<!-- The base XML -->
<MainTag>
<level1 EName="XYZ" ESurname="ABC">
<Desig>PL</Desig>
<Level2>
<Ele1 attri1 ="100" attri2="200"/>
<Ele1 attri1 ="300" attri2="400"/>
</Level2>
<Level3>
<Ele1 attri1 ="500" attri2="600"/>
<Ele1 attri1 ="700" attri2="800"/>
</Level3>
</level1>
<level1 EName="LMN" ESurname="PQR">
<Desig>CTO</Desig>
<Level2>
<Ele1 attri1 ="900" attri2="1000"/>
<Ele1 attri1 ="1100" attri2="1200"/>
</Level2>
<Level3>
<Ele1 attri1 ="1300" attri2="1400"/>
<!-- Attention : Look here the corresponding elements is missing -->
</Level3>
</level1>
</MainTag>


<!-- if it would have been single child level then I would have used the following -->
<xsl:template match="/">
EName,ESurname,Desig,Level2_Attrib1,Level2_Attrib2,Level3_Attrib1,Level3_Attrib2<br/>
<xsl:for-each select="MainTag/level1">
<xsl:variable name="tmp_EName" select="@EName"/>
<xsl:variable name="tmp_ESurname" select="@ESurname"/>
<xsl:variable name="tmp_Desig" select="Desig"/>
<xsl:for-each select="Level2/Ele1">
<xsl:value-of select="$tmp_EName"/>,
<xsl:value-of select="$tmp_ESurname"/>,
<xsl:value-of select="@attri1"/>,
<xsl:value-of select="@attri2"/>
<br/>
</xsl:for-each>
</xsl:for-each>
</xsl:template>

And the expected result is
Ename,ESurname,Level2_Attri1,Level2_Attri2,Level3_Attri1,Level3_Attri2

XYZ,ABC,100,200,500,600
XYZ,ABC,300,400,700,800
LMN,PQR,900,1000,1300,1400
LMN,PQR,1100,1200,,


Points to notice
1. When no matching elements found just print null
2. If it would have been just single level for eg. Level2 then no problem and its a simple for loop. However we have 2 child nodes

Please Help

Postnext
Minollo I.Subject: Help required on Multiple child processings
Author: Minollo I.
Date: 28 Dec 2005 03:17 PM
Something like this?

<xsl:template match="/">
EName,ESurname,Desig,Level2_Attrib1,Level2_Attrib2,Level3_Attrib1,Level3_Attrib2<br/>
<xsl:for-each select="MainTag/level1">
<xsl:variable name="tmp_EName" select="@EName"/>
<xsl:variable name="tmp_ESurname" select="@ESurname"/>
<xsl:variable name="tmp_Desig" select="Desig"/>
<xsl:for-each select="Level2/Ele1">
<xsl:value-of select="$tmp_EName"/>,
<xsl:value-of select="$tmp_ESurname"/>,
<xsl:value-of select="@attri1"/>,
<xsl:value-of select="@attri2"/>,
<xsl:variable name="eleIndex" select="position()"/>
<xsl:variable name="Level3" select="../../Level3/Ele1[$eleIndex]"/>
<xsl:value-of select="$Level3/@attri1"/>,
<xsl:value-of select="$Level3/@attri2"/>
<br/>
</xsl:for-each>
</xsl:for-each>
</xsl:template>

Posttop
Shailendra GodboleSubject: Help required on Multiple child processings
Author: Shailendra Godbole
Date: 28 Dec 2005 03:41 PM
You are god for me. thanks a lot dude I was finding some solution round and round near to this but this was awesome

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.