This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: XSLT template from XSLT + XML
- From: Jeni Tennison <jeni at jenitennison dot com>
- To: "Michael Semcheski" <mhs at aylix dot com>
- Cc: xsl-list at lists dot mulberrytech dot com
- Date: Mon, 30 Sep 2002 23:31:30 +0100
- Subject: Re: [xsl] XSLT template from XSLT + XML
- Organization: Jeni Tennison Consulting Ltd
- References: <006801c268b7$ea9c7060$c701a8c0@aylix.com><163364441819.20020930212010@jenitennison.com><05dd01c268cf$96dd9c20$c701a8c0@aylix.com>
- Reply-to: xsl-list at lists dot mulberrytech dot com
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