[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: XSLT template from XSLT + XML

Subject: Re: XSLT template from XSLT + XML
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Mon, 30 Sep 2002 23:31:30 +0100
conditional identity
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.