W3C home > Mailing lists > Public > xmlschema-dev@w3.org > February 2008

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>


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

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 11 January 2011 00:15:02 GMT