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:styleshe et ...>
<!-- 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