adding new parent element by matching child attribute value

Discussion in 'XML' started by madmaler@googlemail.com, Feb 19, 2008.

  1. Guest

    Hallo NG,

    I´m looking for a solution with xslt do transform this input xml
    document:

    <doc>
    <title>Titel</title>
    <list change="deleted" type="description">
    <item id="1">
    <para>
    TEXT TEXT TEXT
    </para>
    </item>
    </list>
    <para>TEXT TEXT TEXT</para>
    </doc>

    into:
    <doc>
    <title>Titel</title>
    <REMOVE>
    <list type="description">
    <item id="1">
    <para>
    TEXT TEXT TEXT
    </para>
    </item>
    </list>
    </REMOVE>
    <para>TEXT TEXT TEXT</para>
    </doc>

    Thanks for help

    Tobi
    , Feb 19, 2008
    #1
    1. Advertising

  2. Pavel Lepin Guest

    <> wrote in
    <>:
    > <doc>
    > <title>Titel</title>
    > <list change="deleted" type="description">
    > <item id="1">
    > <para>
    > TEXT TEXT TEXT
    > </para>
    > </item>
    > </list>
    > <para>TEXT TEXT TEXT</para>
    > </doc>


    Identity & exclusion.

    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="@*|node()">
    <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
    </xsl:template>
    <xsl:template match="*[@change='deleted']">
    <REMOVE>
    <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
    </REMOVE>
    </xsl:template>
    <xsl:template match="@change[.='deleted']"/>
    </xsl:stylesheet>

    --
    When all you have is a transformation engine, everything
    looks like a tree.
    Pavel Lepin, Feb 19, 2008
    #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. leon
    Replies:
    0
    Views:
    423
  2. Replies:
    2
    Views:
    1,067
    Henry S. Thompson
    Mar 6, 2006
  3. Replies:
    4
    Views:
    2,515
  4. Noel Dolan
    Replies:
    0
    Views:
    217
    Noel Dolan
    Jul 18, 2004
  5. Bitswapper
    Replies:
    5
    Views:
    119
    Prasad, Ramit
    Aug 27, 2013
Loading...

Share This Page