How to strip - and # using xslt

Hell Experts

I Have an xml to xml conversion where i need to copy entire xml As it is but need to strip hypen from bank account numbers and # from Address.

To explain it clearly attached is the source xml. I want the target to be exactly same except that i want to avoid # in field StrtNm (address field) and - in  <Othr/Id>618-401517-001</Id></Othr> (bank account field).

Bottom line is Street address from below part of xml has #. I want that to be stripped

 <PstlAdr>
                  <StrtNm>3 Killiney Road, #07-01 Winsland House I</StrtNm>
                  <PstCd>239519</PstCd>
                  <TwnNm>Singapore</TwnNm>
                  <Ctry>SG</Ctry>
  </PstlAdr>

And bank account no (618-401517-001) form below part of xml has '-' I want that to be stripped.

<CdtrAcct>
               <Id>
                  <Othr>
                     <Id>618-401517-001</Id>
                  </Othr>
               </Id>
               <Tp>
                  <Cd>SACC</Cd>
               </Tp>
               <Ccy>SGD</Ccy>
               <Nm>Winsland Investment PTE LTD</Nm>
            </CdtrAcct>


Below is the code i am using at them moment to copy xml as it is. Can any one please update below code to accomplish above.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:wd="urn:com.workday/bsvc"
    xmlns:etv="urn:com.workday/etv" exclude-result-prefixes="xs" version="2.0">
    <xsl:output method="xml"  indent="yes"/>
    <!-- identity transform -->
    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node() "/>
        </xsl:copy>
    </xsl:template>
   
    <xsl:template match="text()">
        <xsl:value-of select="normalize-space()" />
    </xsl:template>
 </xsl:stylesheet>


Thanks in advance for help,
Sridar
SG_ACH_01_09.pgp
sridhar RAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gertone (Geert Bormans)Information ArchitectCommented:
The beauty of the identity transform approach you are using is that you can easily "specialize" the processing of some elements by being more specific in an additional template

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:wd="urn:com.workday/bsvc" 
    xmlns:etv="urn:com.workday/etv" 
    xmlns:pain="urn:iso:std:iso:20022:tech:xsd:pain.001.001.03"
    exclude-result-prefixes="xs" version="2.0">
    
    <xsl:strip-space elements="*"/>
    <xsl:output method="xml"  indent="yes"/>
    
    <!-- identity transform -->
    
    <xsl:template match="*">
        <xsl:copy>
            <xsl:copy-of select="@*"/>
            <xsl:apply-templates select="node() "/>
        </xsl:copy>
    </xsl:template>
    
    <xsl:template match="comment() | processing-instruction()">
        <xsl:copy-of select="."/>
    </xsl:template>
    
    <xsl:template match="text()">
        <xsl:value-of select="normalize-space()"/>
    </xsl:template>
    
    <xsl:template match="pain:StrtNm">
        <xsl:copy>
            <xsl:copy-of select="@*"/>
            <xsl:value-of select="normalize-space(translate(., '#', ''))" />
        </xsl:copy>
    </xsl:template>

    <xsl:template match="pain:CdtrAcct/pain:Id/pain:Othr/pain:Id">
        <xsl:copy>
            <xsl:copy-of select="@*"/>
            <xsl:value-of select="normalize-space(translate(., '-', ''))" />
        </xsl:copy>
    </xsl:template>
    
    
        
</xsl:stylesheet>

Open in new window


I cleaned up the rest of your code as well, because you had ambiguous rules in there

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sridhar RAuthor Commented:
Hi Geert,

Thanks a ton for help. this code is working perfectly.

Best Regards,
Sridhar
Gertone (Geert Bormans)Information ArchitectCommented:
welcome
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
XML

From novice to tech pro — start learning today.