Re: [xsl] copying <xsl:stylesheet> tag to output xsl file

Subject: Re: [xsl] copying <xsl:stylesheet> tag to output xsl file
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Wed, 2 Jan 2002 14:47:13 +0000
Hi Tony,

> Can some one tell me a way by which i can copy the <xsl:stylesheet>
> element to the output XSL file, & apply the templates on to the XML
> file so that the output of comes between
> <xsl:stylesheet version="1.0"  xmlns:my="http://mysite.com/mynamespace";>
>         <!-- output from the XML file after applying the templates -->
> </xsl:stylesheet>
> tags.

The xsl:apply-templates applies templates to the children of the
xsl:stylesheet element because that's the current node at the point
where the xsl:apply-templates is used.

To apply templates to some other nodes, you need to select those nodes
explicitly. I'd store the document element of the XML file in a
variable, and then apply templates to that element, as follows:

<xsl:template match="/">
  <xsl:variable name="XMLcontent" select="*" />
  <xsl:for-each select="document('')/xsl:stylesheet">
    <xsl:copy>
      <xsl:apply-templates select="$XMLcontent" />
    </xsl:copy>
  </xsl:for-each>
</xsl:template>

I hope that helps,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread