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

RE: search and replace kind of operations with XML

From: Michael Kay <mike@saxonica.com>
Date: Thu, 7 Feb 2008 09:45:26 -0000
To: "'dave'" <ceek63@yahoo.com>, <xmlschema-dev@w3.org>
Message-ID: <013501c8696e$2b28eac0$6401a8c0@turtle>
RE: search and replace kind of operations with XML


I'm not sure why you're asking on an XML Schema list. 

I can't comment on XmlBeans, but you could do this either in XSLT or XQuery.
In my view XSLT works better than XQuery for this kind of transformation,
because of its built-in mechanism for doing a recursive descent of the tree,
applying rules as you go.

Typically you start with a rule that matches anything and copies it without
change, recursing to process the next level:

<xsl:template match="*">
  <xsl:copy>
    <xsl:apply-templates/>
  </xsl:copy>
</xsl:template>

(there are variations of this depending on whether and how you want to
process attributes)

and then you provide specific rules for each kind of element that needs to
be changed. For example the following rule changes <PRICE>12.00</PRICE> to
<cost>10.00</cost>

<xsl:template match="PRICE">
  <cost>
    <xsl:value-of select="format-number(. - 2, '#.00')"/>
  </cost>
</xsl:template>

Hope this helps.

Michael Kay
http://www.saxonica.com/
Received on Thursday, 7 February 2008 09:45:35 GMT

Subscribe to the Stylus Scoop newsletter for helpful XML tips and tutorials.
Email
First Name
Last Name
Company

Download Stylus Studio 6 XML Enterprise Edition

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-2007 All Rights Reserved.