Replacing elements

Discussion in 'XML' started by miroslaw.rusin@mensa.org.pl, Jun 21, 2006.

  1. Guest

    Hi mates! :)

    The challange is like this: how to replace only one element in the
    whole tree to something else?

    Example:

    Input:
    <?xml version="1.0"?>
    <html>
    <head></head>
    <body>
    <b> some<u>thing</ul> </b>
    </body>
    </html>

    into:
    <?xml version="1.0"?>
    <html>
    <head></head>
    <body>
    <strong> some<u>thing</ul> </strong>
    </body>
    </html>

    (<b> -> <strong>) ?

    Mirek
    , Jun 21, 2006
    #1
    1. Advertising

  2. wrote:


    > The challange is like this: how to replace only one element in the
    > whole tree to something else?


    > (<b> -> <strong>) ?


    <xsl:template match="b">
    <strong>
    <xsl:apply-templates select="@* | node()" />
    </strong>
    </xsl:template>
    then you need the identity transformation for the rest
    <xsl:template match="@* | node()">
    <xsl:copy>
    <xsl:apply-templates select="@* | node()" />
    </xsl:copy>
    </xsl:template>


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Jun 21, 2006
    #2
    1. Advertising

  3. Guest

    Problem solved. The trick is to simply use:

    <xsl:element name="{name()}">
    <xsl:apply-templates />
    </xsl:element>
    , Jun 21, 2006
    #3
  4. wrote:
    > Problem solved. The trick is to simply use:
    >
    > <xsl:element name="{name()}">
    > <xsl:apply-templates />
    > </xsl:element>


    That isn't namespace-sensitive. You want to set the namespace URI as
    well. At which point, you've essentially reinvented xsl:copy.

    You also probably need to copy attributes.

    Martin's answer is a cleaner one.
    Joe Kesselman, Jun 21, 2006
    #4
  5. Guest

    Thank you, you're 100% right.
    , Jun 22, 2006
    #5
    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. Wolfgang Lipp
    Replies:
    1
    Views:
    386
    Patrick TJ McPhee
    Jan 30, 2004
  2. Wolfgang Lipp
    Replies:
    0
    Views:
    458
    Wolfgang Lipp
    Jan 28, 2004
  3. Ultrus
    Replies:
    4
    Views:
    2,487
    Stefan Behnel
    Aug 30, 2007
  4. Rob Meade

    Replacing - and not Replacing...

    Rob Meade, Apr 5, 2005, in forum: ASP General
    Replies:
    5
    Views:
    251
    Chris Hohmann
    Apr 11, 2005
  5. Jen
    Replies:
    7
    Views:
    100
Loading...

Share This Page