Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
|
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 20th, 2006, 10:46 AM
Authorized User
 
Join Date: Sep 2006
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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">
 <OrderHead>
 <Schema>
  <Version>1</Version>
  </Schema>
 <MessageReferences>
  <MessageID>OCP326</MessageID>
  <MessageDate>2006-09-19 10:00</MessageDate>
  </MessageReferences>
  <OrderType Code="220" />
 <OrderCurrency>
  <Currency Code="EUR" />
  </OrderCurrency>
  </OrderHead>
 <OrderReferences>
  <BuyersOrderNumber>M.CEEX060913.014</BuyersOrderNumber>
  </OrderReferences>
  <OrderDate>2006-09-18 00:00</OrderDate>
 <Sender>
 <SenderReferences>
  <GLN>PT5003648774470573</GLN>
  </SenderReferences>
  </Sender>
 <Receiver>
 <ReceiverReferences>
  <GLN>PT5002232382790476</GLN>
  </ReceiverReferences>
  </Receiver>
 <Supplier>
 <SupplierReferences>
  <TaxNumber>PT500223238</TaxNumber>
  <GLN>PT5002232382790476</GLN>
  </SupplierReferences>
  </Supplier>
 <Buyer>
 <BuyerReferences>
  <TaxNumber>PT500364877</TaxNumber>
  <GLN>PT5003648774470573</GLN>
  </BuyerReferences>
  </Buyer>
 <Delivery>
 <DeliverTo>
 <DeliverToReferences>
  <GLN>PT5003648774470573</GLN>
  </DeliverToReferences>
  <Party>OCP - MAIA</Party>
 <Address>
  <Street>Rua do Barr!eiro, 179</Street>
  <City>Maia</City>
  <PostCode>4470-573</PostCode>
  <Country Code="PT" />
  </Address>
  </DeliverTo>
  </Delivery>
 <InvoiceTo>
 <InvoiceToReferences>
  <TaxNumber>PT500364877</TaxNumber>
  <GLN>PT5003648774470573</GLN>
  </InvoiceToReferences>
  </InvoiceTo>
 <OrderLine>
  <LineNumber>1</LineNumber>
 <OrderLineReferences>
  <TypeOfDestinationMarket>A</TypeOfDestinationMarket>
  </OrderLineReferences>
 <Product>
  <TradeUnitCode>5091889</TradeUnitCode>
  <Description>DIFFERIN CREME 0,1% 60GR.</Description>
  </Product>
 <Quantity>
  <Amount UOMCode="PCE">110!.0000</Amount>
  </Quantity>
 <Price>
  <UnitPrice UOMCode="PCE">782.000000</UnitPrice>
  </Price>
 <Delivery>
  <LatestAcceptableDate>2006-09-13 00:00</LatestAcceptableDate>
  </Delivery>
  </OrderLine>
 <OrderLine>
  <LineNumber>2</LineNumber>
 <OrderLineReferences>
  <TypeOfDestinationMarket>A</TypeOfDestinationMarket>
  </OrderLineReferences>
 <Product>
  <TradeUnitCode>5091780</TradeUnitCode>
  <Description>DIFFERIN GEL 0,1% 60GR.</Description>
  </Product>
 <Quantity>
  <Amount UOMCode="PCE">220.0000</Amount>
  </Quantity>
 <Price>
  <UnitPrice UOMCode="PCE">1656.000000</UnitPrice>
  </Price>
 <Delivery>
  <LatestAcceptableDate>2006-09-13 00:00</LatestAcceptableDate>
  </Delivery>
  </OrderLine>
 <OrderTotal>
  <NumberOfLines>2</NumberOfLines>
  </OrderTotal>
  </Order>

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

Can someone help me please.

 
Old October 20th, 2006, 10:58 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

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
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old October 20th, 2006, 11:01 AM
Authorized User
 
Join Date: Sep 2006
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

 
Old October 20th, 2006, 11:20 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Well I would use the identity transform and add one template to match the text nodes:
Code:
<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:copy>

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

--

Joe (Microsoft MVP - XML)
 
Old October 20th, 2006, 11:27 AM
Authorized User
 
Join Date: Sep 2006
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.

 
Old October 20th, 2006, 11:30 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

How are you transforming and viewing the output?

--

Joe (Microsoft MVP - XML)
 
Old October 20th, 2006, 11:32 AM
Authorized User
 
Join Date: Sep 2006
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

in a text file

 
Old October 20th, 2006, 11:45 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

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.

HOW ARE YOU PERFORMING THE TRANSFORM?
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)
 
Old October 20th, 2006, 11:47 AM
Authorized User
 
Join Date: Sep 2006
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

 
Old October 20th, 2006, 12:07 PM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

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

--

Joe (Microsoft MVP - XML)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple String Replace berna_isct XSLT 5 May 20th, 2008 02:47 AM
Replace string with a control shenku ASP.NET 1.0 and 1.1 Professional 3 August 22nd, 2005 09:20 AM
replace string value str33ts XSLT 1 April 22nd, 2005 04:01 AM
how to replace a string with another string/number crmpicco Javascript How-To 4 March 14th, 2005 12:59 PM
String.replace() method JohnD Javascript 0 August 20th, 2004 06:46 AM





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