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
Sushant PrabhuSubject: adding a whole new hierarchy in xml transformation
Author: Sushant Prabhu
Date: 29 Nov 2006 01:40 AM
Hi All,

I have a scenario where in I am doing xml to xml transformation via XSLT.

I am able to achieve it appropriately as per the current requirements.

After transformation my new xml looks like this. I have used the ancestor xslt element for rendering the new xml.

***************************
<NewXML blah="something">
<name>First</name>
</NewXML>

<NewXML blah="something">
<name>Second</name>
</NewXML>

<NewXML blah="something">
<name>Third</name>
</NewXML>

**************************

This is what i have achieved from transformation of old xml tags into new.

Now the next step is to create a whole new hierarchy of tags based on the above. Here the value "First" is how i got above from the transformed new XML which is a node value. This is the new xml I need to append.
*******************************************
<root>
<parent>First</parent>
<name> Child1 </name>
</root>

<root>
<parent>First/Child1</parent>
<name> Child2 </name>
</root>

<root>
<parent>First/Child1</parent>
<name> Child22 </name>
</root>

<root>
<parent>First/Child1/Child22</parent>
<name> Chil3 </name>
</root>

<root>
<parent>First/Child1/Child22</parent>
<name> Chil33 </name>
</root>

<root>
<parent>First/Child1/Child22</parent>
<name> Chil333 </name>
</root>

*******************************************
This I have to do for every transformed tag i.e. First, Second, Third etc. The same set of XML tags as mentioned above needs to be generated.

Now should I be hard coding the same in my XSL transformation where in I convert the old xml to new or can i automate this process by specifying the hierarchy in some variables or arrays & then jus creating place holders which can be filled from the data from arrays/variables.

Currently what I have done is hard code something like this
*****************************************
<xsl:variable name="temp"> <xsl:for-each select="ancestor::*"> <xsl:value-of select="normalize-space(node_name)"/> <xsl:if test = "position() != '1' "> <xsl:text>/</xsl:text>
</xsl:if> </xsl:for-each>
</xsl:variable>

<root>
<parent><xsl:value-of select="$temp"/></parent>
<name> Child1 </name>
</root>

<root>
<parent>
<xsl:value-of select="$temp"/>
<xsl:text>/Child1</xsl:text> </parent>
<name> Child2 </name>
</root>

and so on
******************************************

This amounts to a lot of hard coding & not very flexible. Do post your thoughts if there is a better solution.
As I have to create the same set of hierarchial xml tags for each node that I transform I want to just create a template. This template is gonna be huge because of a long hierarchy where in I got to create.

This is the pre defined hierarchy which I need to include under every transformed node.
Child1/
Child2/
Child22/
Child3/
Child33/
Child333/


Do post your suggestions
Regards,




Posttop
James DurningSubject: adding a whole new hierarchy in xml transformation
Author: James Durning
Date: 30 Nov 2006 01:21 PM
I find it hard to track what exactly you are transforming, and what is your expected output.

Could you use a globally unique node id to reference parent nodes as opposed to paths?
eg. have a parent-id attribute, and an id attribute for each node.

 
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.