[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:49:13 -0500
Re:  How to insert a set nodes under the root of an  ar
On Fri, Jan 07, 2011 at 04:39:18PM -0500, Beck, Jeff (NIH/NLM/NCBI) [E] scripsit:
> On 1/7/11 4:27 PM, "Graydon" <graydon@xxxxxxxxx> wrote:
[I make a dumb mistake answering a question]
> There is only one child of the root node, but you still can match it. 

Well, sure, but if you produce output with two element children of the
root node -- two document nodes -- that's not well formed, so it's not
XML anymore.  Which is what my first reply did.

> This modification of your original (along with the identity template)
> works nicely for me with XSL1 in xalan. The advantage of matching the
> root element is that there might not be any children.

He did specify that it there was guaranteed to be at least one child,
but yes.

The first match I gave is a match on the document node; / is the root
node, /* is the document node, at least per XPath 2 terminology.  XPath
1 is of course using different terminology. :)

> I think you'll need to write your fixed content in the copy - and don't
> forget to process the attributes before you write any children
> 
> <!-- match the first element child of the root node -->
> <xsl:template match="/*[1]">
>     <!-- but don't lose the former first element child of the root node -->
>     <xsl:copy>
>         <xsl:apply-templates select="@*"/>
>         <element> Your fixed content goes here as literal result elements
> </element>
>         <xsl:apply-templates select="node()"/>
>     </xsl:copy>
> 
> </xsl:template>

Wheras that ought to work, because it's making sure everything stays in
the document node.

-- 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.