Injecting a copy of a value using a xslt

K

krach.aran

I am using a xml with the following structure :

<xml ....>
<mainnode>
<node1>value1<node1>
<node2>
<subnode1>val</subnode1>
</node2>
<node3>value3</node3>
<node4>value4</value4>
</mainnode>

This xml i want to transform to

<xml ....>
<mainnode>
<node1>value1<node1>
<node2>
<subnode1>val</subnode1>
</node2>
<node3>value3</node3>
<NEWNODE>value1</NEWNODE>
<node4>value4</value4>
</mainnode>

where a newnode is created after a specific node (node3), and contains
the value of node1.
I am not a XSLT guru so i'm gonna need some help.
TIA

Otto Beragg
 
J

Joseph Kesselman

Start with the XSLT identity transformation (see the spec, or websearch).

Add a template that recognizes the node you want to process differently.
Modify its operation appropriately. In this case, the easiest thing
might be to have that match node3 and have it output your new node after
it does the basic recursive copy.

Retrieve the new node's value by using xsl:select or xsl:value-of with
the appropriate XPath.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,815
Latest member
treekmostly22

Latest Threads

Top