Adding a node in xml

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • N9

    Adding a node in xml

    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
  • Joseph J. Kesselman

    #2
    Re: Adding a node in xml

    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.

    Comment

    Working...