Adding a node in xml

N

N9

Hi,

I got a xml fil:

<Ordbog ModuleId="4">
<WordSet Id="cec36468-a624-46af-a51e-e583f52efab6" />
<Ord>return</Ord>
<Beskrivelse>
test1
</Beskrivelse>
<WordSet Id="009f4be5-0481-4a04-a8d2-f817c7e6d48e" />
<Ord>tow</Ord>
<Beskrivelse>
Fem
</Beskrivelse>
<WordSet Id="c7b6ae0e-1f74-43d3-839b-24a39f259cb6" />
</Ordbog>

I like to adding a node with xslt, so the result looks like that.

<Ordbog ModuleId="4">
<Ord>
<WordSet Id="cec36468-a624-46af-a51e-e583f52efab6" />
<Ord>return</Ord>
<Beskrivelse>
test1
</Beskrivelse>
</Ord>
<Ord>
<WordSet Id="009f4be5-0481-4a04-a8d2-f817c7e6d48e" />
<Ord>tow</Ord>
<Beskrivelse>
Fem
</Beskrivelse>
<WordSet Id="c7b6ae0e-1f74-43d3-839b-24a39f259cb6" />
</Ord>
</Ordbog>

It's that possible ??

regards
N9
 
J

Joseph J. Kesselman

It's that possible ??

To "add a node" in XSLT, start with the identity transformation (see any
decent XSLT tutorial), then add a template which expresses the exception
to that copy-without-changing process. In this case, you'd add a
template to wrap the content of Ordbog in an additional Ord element:

<xsl:template select="Ordbog">
<ord>
<xsl:apply-templates>
</ord>
</xsl:template>

or something of that sort. (Remember, this has to appear IN ADDITION to
the identity template, since that handles all the other cases.)

Note that this generates a new document with the desired change, rather
than directly altering the original document. Replacing the old document
with the new one is your responsibility.
 

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

No members online now.

Forum statistics

Threads
473,778
Messages
2,569,605
Members
45,237
Latest member
AvivMNS

Latest Threads

Top