Adding a node in xml

Discussion in 'XML' started by N9, Apr 16, 2008.

  1. N9

    N9 Guest

    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
    N9, Apr 16, 2008
    #1
    1. Advertising

  2. > 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.
    Joseph J. Kesselman, Apr 16, 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. Replies:
    0
    Views:
    1,442
  2. Tjerk Wolterink
    Replies:
    2
    Views:
    1,418
    Dimitre Novatchev
    Aug 24, 2006
  3. Rajarshi
    Replies:
    1
    Views:
    536
    Gabriel Genellina
    Feb 11, 2007
  4. Martin Honnen

    Re: Reading XML Node-by-Node

    Martin Honnen, Nov 12, 2008, in forum: ASP .Net
    Replies:
    0
    Views:
    385
    Martin Honnen
    Nov 12, 2008
  5. Geagleeye

    how to creating new node inside a xml node

    Geagleeye, Aug 2, 2006, in forum: ASP General
    Replies:
    2
    Views:
    197
    Geagleeye
    Aug 3, 2006
Loading...

Share This Page