[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: How to insert a set nodes under the root of an ar

Subject: Re: How to insert a set nodes under the root of an arbitrary XML using XSL?
From: Graydon <graydon@xxxxxxxxx>
Date: Fri, 7 Jan 2011 16:16:16 -0500
Re:  How to insert a set nodes under the root of an  ar
On Fri, Jan 07, 2011 at 04:07:43PM -0500, William C Thompson scripsit:
> I would love to know how to (using XSL) insert a pre-determined node a
> (with children b and c) as a child of the root node of an arbitrary XML.  I
> know how to apply the XSL once I've got it.  I just need help with the XSL.
> All the examples I'm finding online assume a pre-determined XML, which I
> cannot in this case.
[snip illustrative abstract example]
> Most importantly, please note that any solutions with hard-coded references
> to any node names (other than those I want to insert) are not usable for
> me.  I have no control over the schema of the XML into which I'm sticking
> these other nodes.  I know only that it's a valid XML file and the root has
> at least one child.  The above example is a purely made up example designed
> to illustrate the question.

You can do this with two templates, at least if I understand the question:

<!-- Our old friend the identity transform -->
<xsl:template match="node()|@*">
    <xsl:copy>
        <xsl:apply-templates select="node()|@*"/>
    </xsl:copy>
</xsl:template>

<!-- match the first element child of the root node -->
<xsl:template match="/*[1]">
    <element> Your fixed content goes here as literal result elements </element>
    <!-- but don't lose the former first element child of the root node -->
    <xsl:copy>
        <xsl:apply-templates select="node()|@*"/>
    </xsl:copy>
</xsl:template>

-- Graydon

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.