XSL to convert an XML in similar format's without changing any tags

A

Amit

Hi All,

I am stuck in a pretty simple problem.

I need an XSL to convert an XML with similar format's and some
additions, please consider the following example to understand my
issue.

Input XML

<Root>
<Name>amit</Name>
<Name1>gupta</Name1>
<other>bla bla bla</other>
<Root>

Output Desired XML

<Root>
<Name>amit</Name>
<Name1>gupta</Name1>
<other>bla bla bla</other>
<AdditionalTag> Addition to previous xml </AdditionalTag>
<Root>

I know, how to add new tag's. My problem is that I want some generic
XSL to convert, all tag's in input xml, no matter how many they are,
to output xml, with some additional tags.

Thanks in Advance,
Regards,
-Amit Gupta
 
M

Martin Honnen

Amit said:
<Root>
<Name>amit</Name>
<Name1>gupta</Name1>
<other>bla bla bla</other>
<Root>

Output Desired XML

<Root>
<Name>amit</Name>
<Name1>gupta</Name1>
<other>bla bla bla</other>
<AdditionalTag> Addition to previous xml </AdditionalTag>
<Root>

<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>

<xsl:template match="Root">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
<AdditionalTag> Addition to previous xml </AdditionalTag>
</xsl:copy>
</xsl:template>

should do it. If there are different kind of root elements then it
should also suffice to use e.g.

<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>

<xsl:template match="/*">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
<AdditionalTag> Addition to previous xml </AdditionalTag>
</xsl:copy>
</xsl:template>
 

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,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top