[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: "Narang, Prateek" <PNarang@xxxxxxxxxxxxxxxxxxx>
Date: Fri, 24 Sep 2004 11:32:20 +0530
xsl add element
I think this code will work fine according to your requirement.

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>

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

  <xsl:template match="ROWSET">
    <xsl:element name="TABLE">
      <xsl:text>mytable</xsl:text>
    </xsl:element>
	<xsl:copy-of select="."/>
  </xsl:template>
</xsl:stylesheet>

Regds
--prateek--

Prateek Narang
Professional Services
Innodata Isogen
4th Floor, Gateway Tower
R Block, DLF City, Phase-III
Gurgaon, Haryana - 122 002
Phone:  +(091) 124-2562801
Fax:      +(091) 124-2356001
Cell:      +(091)  9868350569

www.innodata-isogen.com


-----Original Message-----
From: Garry Cronin [mailto:garry.cronin@xxxxxxxxxx]
Sent: Thursday, September 23, 2004 8:23 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re:  problem adding a new element to an XML document using
xsl:element...

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.