p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   XML (http://p2p.wrox.com/forumdisplay.php?f=91)
-   -   Help in instruction string-replace (http://p2p.wrox.com/showthread.php?t=49269)

hugoscp October 20th, 2006 10:46 AM

Help in instruction string-replace
Can someone help me in the instruction string-replace.
I have this xml file:

<?xml version="1.0" encoding="ISO-8859-1" ?>
 <Order xmlns:xsd="http://www.w3.org/2000/10/XMLSchema">
  <MessageDate>2006-09-19 10:00</MessageDate>
  <OrderType Code="220" />
  <Currency Code="EUR" />
  <OrderDate>2006-09-18 00:00</OrderDate>
  <Party>OCP - MAIA</Party>
  <Street>Rua do Barr!eiro, 179</Street>
  <Country Code="PT" />
  <Description>DIFFERIN CREME 0,1% 60GR.</Description>
  <Amount UOMCode="PCE">110!.0000</Amount>
  <UnitPrice UOMCode="PCE">782.000000</UnitPrice>
  <LatestAcceptableDate>2006-09-13 00:00</LatestAcceptableDate>
  <Description>DIFFERIN GEL 0,1% 60GR.</Description>
  <Amount UOMCode="PCE">220.0000</Amount>
  <UnitPrice UOMCode="PCE">1656.000000</UnitPrice>
  <LatestAcceptableDate>2006-09-13 00:00</LatestAcceptableDate>

I would like to replace in the Order the ! caracter by a backspace.

Can someone help me please.

mhkay October 20th, 2006 10:58 AM

There is no string-replace instruction. You can substitute one character for another using the translate() function in XPath. However, backspace is not a legal character in XML 1.0, so you cannot replace "!" by backspace.

Michael Kay
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference

hugoscp October 20th, 2006 11:01 AM

Ok and how do i use the function translate to replace ! by ? for example

joefawcett October 20th, 2006 11:20 AM

Well I would use the identity transform and add one template to match the text nodes:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:param name="from" select="'!'"/>
  <xsl:param name="to" select="'?'"/>

  <xsl:template match="node()|@*">


      <xsl:apply-templates select="node()|@*"/>
    Templates to match nodes that need changing go here
  <xsl:template match="text()">
    <xsl:value-of select="translate(., $from, $to)"/>


Joe (Microsoft MVP - XML)

hugoscp October 20th, 2006 11:27 AM

i get only this: <?xml version="1.0" encoding="UTF-16"?>

And he doesn´t replace the ! by ? and i would like to replace in all the xml file.

joefawcett October 20th, 2006 11:30 AM

How are you transforming and viewing the output?


Joe (Microsoft MVP - XML)

hugoscp October 20th, 2006 11:32 AM

in a text file

joefawcett October 20th, 2006 11:45 AM

I don't wish to appear rude but I'm trying to help and you just provide a four word response... As far as I know no text file has the ability to transform XML single-handed.

What processor, what language etc. I just ran that transform using both Visual Studio and Saxon (with a small alteration as it was a version 2.0 processor) and got the same results.


Joe (Microsoft MVP - XML)

hugoscp October 20th, 2006 11:47 AM

I then have a vbscript that i run in the windows explorer that transform the xml file using the xsl transformation and i get a text file

joefawcett October 20th, 2006 12:07 PM

Okay, well can we see the relevant bits of code because it works on my machine using msxml version 4?


Joe (Microsoft MVP - XML)

All times are GMT -4. The time now is 07:01 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.