| Subject: Re: [xsl] XSLT template from XSLT + XML From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx> Date: Mon, 30 Sep 2002 23:31:30 +0100 | 
Hi Michael,
> Just out of curiosity, is it possible to create a stylesheet that
> will go in and recreate all elements and attributes? I can see it
> being possible for the elements, but the attributes would be tough,
> unless you can do a for-each select="attributes" type of thing.
Sure. The easiest "identity" stylesheet is:
<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
  <xsl:copy-of select="." />
</xsl:template>
</xsl:stylesheet>
But that just copies everything exactly as it was. If you want to make
a few adjustments, you need to use an "identity template", which you
can override for specific elements and attributes by defining
templates for those elements and attributes:
<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="node() | @*">
  <xsl:copy>
    <xsl:apply-templates select="@* | node()" />
  </xsl:copy>
</xsl:template>
... your overriding templates here ...
</xsl:stylesheet>
You can also copy elements and attributes using xsl:element and
xsl:attribute with attribute value templates in the name and namespace
attributes:
  <xsl:element name="{name()}" namespace="{namespace-uri()}">
    ...
  </xsl:element>
  <xsl:attribute name="{name()}" namespace="{namespace-uri()}" />
though generally xsl:copy is easier.
  
Cheers,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
| Current Thread | 
|---|
| 
 | 
| <- Previous | Index | Next -> | 
|---|---|---|
| Re: [xsl] XSLT template from XSLT +, Michael Semcheski | Thread | Re: [xsl] XSLT template from XSLT +, Wendell Piez | 
| RE: [xsl] conditional inlcudes -is , Robert Koberg | Date | Re: [xsl] XSLT template from XSLT +, Wendell Piez | 
| Month |