By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,190 Members | 1,503 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,190 IT Pros & Developers. It's quick & easy.

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

P: n/a
DR
What is the fastest possible xsl style sheet to add another <boxnode 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
Nov 1 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
DR wrote:
What is the fastest possible xsl style sheet to add another <boxnode 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

<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]
http://www.tkachenko.com/blog | http://www.XmlLab.Net
Nov 1 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.