[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: XSLT template from XSLT + XML
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|