[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
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 >_______________________________________________________________________ >_
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|