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
Conferences Close Tree View
+ Stylus Studio Feature Requests (1192)
+ Stylus Studio Technical Forum (14621)
+ Website Feedback (249)
- XSLT Help and Discussion (7625)
-> + Use of before and after string (3) Sticky Topic
-> - How do I substitute element ty... (1)
-> + How does one add working days ... (4)
-> - Help, I have existing XLT and... (1)
-> + Need help on XSLT issue - (2)
-> + EDI to XML Conversion (7)
-> - XML To JSON Conversion using X... (1)
-> + Formatting Paragraphs to same ... (2)
-> - Grouping of records (1)
-> + Problems with xsd 1.1 (4)
-> + XML to HL7 mapping (3)
-> + XSLT 3 and Iterate (2)
-> + XSL-FO to PDF preview (3)
-> + java.lang.RuntimeException: Er... (2)
-> + Create Acroforms with Stylus X... (2)
-> + How to change XSLT parameter s... (3)
-> + how to change format of the da... (2)
-> + Search "Next 8 Results " doesn... (2)
-> - Support for Git (1)
-> + newbee (8)
-- [1-20] [21-40] [41-60] Next
+ XQuery Help and Discussion (2017)
+ Stylus Studio FAQs (159)
+ Stylus Studio Code Samples & Utilities (364)
+ Stylus Studio Announcements (113)
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

   
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.