Re: [xsl] problem adding a new element to an XML document using xsl:element...

Subject: Re: [xsl] problem adding a new element to an XML document using xsl:element...
From: David Carlisle <davidc@xxxxxxxxx>
Date: Thu, 23 Sep 2004 15:34:42 +0100
> 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