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

Discussion in 'XML' started by Amit, May 31, 2007.

  1. Amit

    Amit Guest

    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
    Amit, May 31, 2007
    #1
    1. Advertising

  2. Re: XSL to convert an XML in similar format's without changing anytags

    Amit wrote:

    > <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>


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, May 31, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Greg Smith
    Replies:
    35
    Views:
    3,180
    Alex Kay
    Oct 24, 2004
  2. Replies:
    1
    Views:
    3,600
    A. Bolmarcich
    May 27, 2005
  3. Replies:
    0
    Views:
    555
  4. Ken Starks
    Replies:
    4
    Views:
    346
    Ken Starks
    Jun 23, 2008
  5. Weng Tianxiang
    Replies:
    7
    Views:
    1,281
    Paul Uiterlinden
    Sep 11, 2009
Loading...

Share This Page