Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XML
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 20th, 2006, 10:46 AM
Authorized User
 
Join Date: Sep 2006
Location: , , .
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.

Reply With Quote
  #2 (permalink)  
Old October 20th, 2006, 10:58 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
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
Reply With Quote
  #3 (permalink)  
Old October 20th, 2006, 11:01 AM
Authorized User
 
Join Date: Sep 2006
Location: , , .
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

Reply With Quote
  #4 (permalink)  
Old October 20th, 2006, 11:20 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
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)
Reply With Quote
  #5 (permalink)  
Old October 20th, 2006, 11:27 AM
Authorized User
 
Join Date: Sep 2006
Location: , , .
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.

Reply With Quote
  #6 (permalink)  
Old October 20th, 2006, 11:30 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

How are you transforming and viewing the output?

--

Joe (Microsoft MVP - XML)
Reply With Quote
  #7 (permalink)  
Old October 20th, 2006, 11:32 AM
Authorized User
 
Join Date: Sep 2006
Location: , , .
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

in a text file

Reply With Quote
  #8 (permalink)  
Old October 20th, 2006, 11:45 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
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)
Reply With Quote
  #9 (permalink)  
Old October 20th, 2006, 11:47 AM
Authorized User
 
Join Date: Sep 2006
Location: , , .
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

Reply With Quote
  #10 (permalink)  
Old October 20th, 2006, 12:07 PM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
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)
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 07:23 AM.


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