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

Re: XML -> XML

Subject: Re: XML -> XML
From: "Steve Muench" <smuench@xxxxxxxxxxxxx>
Date: Wed, 16 Aug 2000 12:58:49 -0700
identity.xsl
| ...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

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.