all groups > dotnet xml > november 2007 >
You're in the

dotnet xml

group:

What is the fastest possible xsl style sheet to add another <box> node under <boxes> ?



What is the fastest possible xsl style sheet to add another <box> node under <boxes> ? DR
10/31/2007 7:42:47 PM
dotnet xml: What is the fastest possible xsl style sheet to add another <box> node under
<boxes> ?

<foo>
<car></car>
<boxes>
<box id="234" />
<box id="75" />
</boxes>
</foo>

here is what i want it to look like after the xsl adds another box node:

<foo>
<car></car>
<boxes>
<box id="89">
<bar id="1" />
<bar id="35" />
</box>
<box id="234" />
<box id="75" />
</boxes>
</foo>

notice that the node i want to insert under /foo/boxes is:

<box id="89">
<bar id="1" />
<bar id="35" />
</box>

and i want it to appear at the top of the list, befor the other two <box>
nodes

Re: What is the fastest possible xsl style sheet to add another <box> node under <boxes> ? Oleg Tkachenko [MVP]
11/1/2007 12:00:00 AM
[quoted text, click to view]

<xsl:stylesheet ...>
<!-- copy all as is -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>

<!-- boxes element is special -->
<xsl:template match="boxes">
<!-- copy boxes element and its attributes -->
<xsl:copy>
<xsl:apply-templates select=@*/>
<!-- append new content -->
<box id="89">
<bar id="1" />
<bar id="35" />
</box>
<!-- process (copy actually) the rest children -->
<xsl:apply-templates select="node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

--
Oleg Tkachenko [XML MVP, MCPD]
AddThis Social Bookmark Button