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

Re: problem adding a new element to an XML document us

Subject: Re: problem adding a new element to an XML document using xsl:element...
From: Garry Cronin <garry.cronin@xxxxxxxxxx>
Date: Thu, 23 Sep 2004 15:52:55 +0100
xsl rowset
Thanks David. I used your suggestion i.e.

<xsl:template match="ROWSET">
  <ROWSET>
  <TABLE>mytable</TABLE>
   <xsl:apply-templates/>
  </ROWSET>
 </xsl:template>

and it works a treat.

I notice I still have to include the <ROWSET> and </ROWSET> literals in the stylesheet. Can't I simply instruct the stylesheet to output the existing ROWSET elements unchanged, without having to repeat them in the stylesheet. The current solution implies that I would have to manually recontruct any attributes the ROWSET element might have in the input XML?

- Garry

David Carlisle wrote:

Any ideas what I'm doing wrong?


two things


a) you want to put your table element before the result of applying
templates to the input, but you have

 <xsl:template match="ROWSET">
  <xsl:element name="TABLE">
     <xsl:text>mytable</xsl:text>
     <xsl:apply-templates/>
   </xsl:element>
 </xsl:template>

which applies templates )inside_ the table element so it puts everything
inside the table so you want

  <xsl:template match="ROWSET">
  <ROWSET>
  <xsl:element name="TABLE">
     <xsl:text>mytable</xsl:text>
   </xsl:element>
   <xsl:apply-templates/>
  </ROWSET>
 </xsl:template>

or equivalently

  <xsl:template match="ROWSET">
  <ROWSET>
  <TABLE>mytable</TABLE>
   <xsl:apply-templates/>
  </ROWSET>
 </xsl:template>

then you are applying templates to the children of ROWSET but you have
no templates matching those elements so you get the result of the
default template, which just results in the character data and no
element markup (compare with the result of a stylesheet that just has an
empty xsl:stylesheet element and no template children).

You could add a template for * that does the identity transform (copied
from the XSLT spec or the archives of this list or the faq) but if you
want the whole tree copied there is no need to use apply templates at
all you can just copy the tree:


<xsl:template match="ROWSET"> <ROWSET> <TABLE>mytable</TABLE> <xsl:copy-of select="*"/> </ROWSET> </xsl:template>

David

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

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.