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">
 <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.


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
http://www.saxonica.com/
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:
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)

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.

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)

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.