aspose file tools*
The moose likes XML and Related Technologies and the fly likes Replicate XML Node using XSL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Replicate XML Node using XSL" Watch "Replicate XML Node using XSL" New topic
Author

Replicate XML Node using XSL

Bhupendra Mehta
Greenhorn

Joined: Oct 29, 2004
Posts: 11
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

Joined: Jun 03, 2000
Posts: 5040
I am not clear on what you mean by the XML 1 and XML 2 files. Could you rephrase your question.

- m


Take a Minute, Donate an Hour, Change a Life
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
Bhupendra Mehta
Greenhorn

Joined: Oct 29, 2004
Posts: 11
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

Joined: Jun 03, 2000
Posts: 5040
Maybe I am missing something but I still don't see how these two files are related.

- m
Bhupendra Mehta
Greenhorn

Joined: Oct 29, 2004
Posts: 11
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
Bartender

Joined: Oct 14, 2005
Posts: 18886
    
    8

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

Joined: Oct 29, 2004
Posts: 11
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
Bartender

Joined: Oct 14, 2005
Posts: 18886
    
    8

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

Joined: Oct 29, 2004
Posts: 11
Paul Is there an email I can email you my xmls & xsl
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18886
    
    8

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

Joined: Oct 29, 2004
Posts: 11
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

Joined: Oct 29, 2004
Posts: 11
Here is part of the XSL file.

Continued....
Bhupendra Mehta
Greenhorn

Joined: Oct 29, 2004
Posts: 11
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Replicate XML Node using XSL