This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes Reusing translated nodes - XSLT newbie Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Reusing translated nodes - XSLT newbie" Watch "Reusing translated nodes - XSLT newbie" New topic
Author

Reusing translated nodes - XSLT newbie

Scott Krasnigor
Greenhorn

Joined: Oct 10, 2005
Posts: 9
I am trying to translate an XML document into a specialized form of XML via XSLT. During the translation process, there are certain cases where I need to reuse a previously translated node and it's children. I am having trouble figuring out how to store the node when it is translated and output it to the new document when needed. Thanks.
vinay kumar
Ranch Hand

Joined: Sep 23, 2006
Posts: 31
Scott,

Already translated node can be accessed by giving absolute xpath (start from root tag like /Root/Child) while translating other node. But remember that you can access data of the source tree but not the target tree while translation process.


<b> holds value '10' but not '100'.

In <xsl:template match="b">, if you want to know what the translated 'a' contains, you obviously need to check if
sachin scored a century or not.

Cheers,
vinay.
[ September 28, 2006: Message edited by: vinay kumar ]
Scott Krasnigor
Greenhorn

Joined: Oct 10, 2005
Posts: 9
Thanks for the reply. I guess I wasn't very clear with my question. Given a node (and children of the node) of xml from the source document, I translate it into the destination document. What I want to do is store that translated node so that I can added it later on without having to re-translate that section. The reasoning being that I need to append the stored translated node to each subsequent translated node. Hope this make sense.
vinay kumar
Ranch Hand

Joined: Sep 23, 2006
Posts: 31
Store the translated node into an xml document and retrive it to copy into destination document (while translation) using document() function.

For eg. to copy your translated doc(stored in trans.xml) to an element 'A'
<A>
<xsl:copy-of select="document('c:/x/trans.xml')"/>
</A>
.....
Or if your tobe copied node and other elements (into which you want to copy) exist in the same file (during same tranlation), put the tobe copied node in a variable and use <xsl:copy-of select="$var"/> where ever needed.

If it isn't make sense, please give your problem with code. I will try to answer..

vinay.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Reusing translated nodes - XSLT newbie
 
Similar Threads
XML Comparison without DTD & XSD and able to return XPath of the Diff Node
Using SAXON as parser
merge XMl documents using schema to determine sequencing
In XSLT , is reference to root node required to access child node of root node ?
Problems converting a node to string