Subject: Re: XML -> XML From: "Steve Muench" <smuench@xxxxxxxxxxxxx> Date: Wed, 16 Aug 2000 12:58:49 -0700 |
| ...maybe change an attribute, say: | | date="some format" | | to | | date="some new format" | | while not touching anything else? Jon, Transformations of this sort are best done as a variation on the identity transformation. If you put the following handy identity transformation into a file like "identity.xsl"... <!-- The Identity Transformation --> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <!-- Whenever you match any node or any attribute --> <xsl:template match="node()|@*"> <!-- Copy the current node --> <xsl:copy> <!-- Including any attributes it has and any child nodes --> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> </xsl:stylesheet> And then build a stylesheet that imports the "identity.xsl" stylesheet as part of it as the one does below, then whatever templates you put in this stylesheet will take precedence over the base (imported) template that is doing the identity transformation of each node. The result is that the tree gets copied verbatim, with the exception of the "overrides" your templates below pick up... <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <!-- Import the identity transformation. --> <xsl:import href="Identity.xsl"/> <!-- | This will match any element's "date" attribute | Make the pattern more specific if this is not appropriate +--> <xsl:template match="@date"> <!-- This will construct a "date" attribute having value of its content --> <xsl:attribute name="date"> <!-- Change what's in here to construct the "new" date format --> <xsl:value-of select="concat('new',.)"/> </xsl:attribute> </xsl:template> </xsl:stylesheet> This will transform a document like: <a date="1"> <b date="2"/> <c> <d date="3"/> </c> </a> into: <a date="new1"> <b date="new2"/> <c> <d date="new3"/> </c> </a> ______________________________________________________________ Steve Muench, Lead XML Evangelist & Consulting Product Manager BC4J & XSQL Servlet Development Teams, Oracle Rep to XSL WG Author "Building Oracle XML Applications", O'Reilly http://www.oreilly.com/catalog/orxmlapp/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
XML -> XML, Jon Wynacht | Thread | Re: XML -> XML, Jeni Tennison |
Passing Variable into an external x, Sia Rahimi | Date | Use of Parameters ...Help! :), Bill Shaw - EBCX |
Month |