Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Replicate XML Node using XSL

 
Bhupendra Mehta
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to replicate a node from an XML with attribute values read from another XML file. Both the input XMLs are huge aprrox 10 - 50 M. What is the best way to accomplish this. With my current stylesheet I get a Stackoverflow error for records over 1400. Here is a sample XML



obviously the dynamic values are read from XML 2.

Thanks for any response.


Edit Comment: Close the code tag.

- m
[ February 15, 2006: Message edited by: Madhav Lakkapragada ]
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not clear on what you mean by the XML 1 and XML 2 files. Could you rephrase your question.

- m
 
Bhupendra Mehta
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I mean is that these are two separate files. for e.g. data.xml (XML 1) and users.xml (XML 2) just means of labelling.
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe I am missing something but I still don't see how these two files are related.

- m
 
Bhupendra Mehta
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Assume node2 from XML 1 as a template for the node I am trying to replicate. The attribute values for that node/children viz sub-node2/@attr3 and sub-node3/@attr are to be picked up from XML 2 (dynamic values) based on some condition. Lets say sub-node2/@attr3 will be populated by users/user/@name.

Hope this better explains it. Thanks.
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're getting a stack overflow error then there's a problem with your XSLT code. But you didn't post any of it so it's hard to say what that might be (except that it might be related to a recursive template).
 
Bhupendra Mehta
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the code which I believe is causing the recursive looping ... this is where I loop through all the users in the users.xml (XML 2)


I guess I'm looking for a better way to loop through all the records in XML 2 without having to do a recursive loop like above.

Thanks for your response
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suppose that could be recursive, but you have left out the code that proves that. Well, anyway, let's assume it's recursive.

The usual way to loop through a set of nodes is by using an <xsl:for-each> element. Or if you're looking for a particular node and XPath doesn't do what you want, you could use an <xsl:key> element. It's hard to suggest what exactly you should do without knowing what you want to do and without knowing how you are doing it now.
 
Bhupendra Mehta
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Is there an email I can email you my xmls & xsl
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, that would be contrary to the point of having a forum. (Besides I don't want multi-megabyte attachments in my inbox.)

You said
The attribute values for that node/children viz sub-node2/@attr3 and sub-node3/@attr are to be picked up from XML 2 (dynamic values) based on some condition.
If I were you I would try to write an XPath expression that represents that condition rather than writing a loop. Or use the <xsl:key> idea.
 
Bhupendra Mehta
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have to send these in multiple posts.

Here is the input XML.

XML 1 (input.xml) where I need to replicate the node content-node with attr create-type="implicit" with data populated from userinfo.xml. All other nodes need to be copied as is.


XML2 (userinfo.xml) is the xml which holds user data to be used while replicating the node.
 
Bhupendra Mehta
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is part of the XSL file.

Continued....
 
Bhupendra Mehta
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Part 2 of the XSL

This code works for about 1000 - 1200 iterations but beyond that I get a StackOverFlow. Thanks for your help and I apologize for the lengthy content.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic