Xslt replace tag -


we have xslt file creates following tags:

<fininstnid>      <bic />  </fininstnid>  

or

<fininstnid>      <bic>bicabc</bic>  </fininstnid>  

this must replaced by:

<fininstnid>      <othr>          <id>notprovided</id>      </othr>  </fininstnid>  

how have change current xslt looks like:

<xsl:template match="/">    <xsl:text disable-output-escaping="yes">&lt;?xml version="1.0" encoding="utf-8"?&gt;</xsl:text>    <xsl:copy-of select="wt:envelope/wt:body/wt:messageparts/*" /> </xsl:template> 

the input xml data must changed looks like:

<document xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" :tech:xsd:pain.001.001.03" xsi:schemalocation="urn:iso:std:iso:20022:tech:xsd:pain.001.001.03 pain.001.001.03.xsd">- <cstmrcdttrfinitn>     <grphdr>         <msgid>pmb000053</msgid>         <credttm>2014-03-06t11:08:10</credttm>         <nboftxs>1</nboftxs>         <ctrlsum>1000</ctrlsum>         <initgpty>              <nm>abc</nm>         </initgpty>     </grphdr> <pmtinf>     <pmtinfid>005320140306</pmtinfid>     <pmtmtd>trf</pmtmtd>     <btchbookg>false</btchbookg>     <nboftxs>1</nboftxs>     <ctrlsum>1000</ctrlsum>     <pmttpinf>         <svclvl>             <cd>sepa</cd>         </svclvl>     </pmttpinf>     <reqdexctndt>2014-03-06</reqdexctndt>     <dbtr>         <nm>typs b.v.</nm>         <pstladr>               <ctry>nl</ctry>               <adrline>street 123 amsterdam</adrline>               <adrline>s</adrline>         </pstladr>     </dbtr>     <dbtracct>          <id>               <iban>nl10abna5555555</iban>          </id>     </dbtracct>     <dbtragt>         <fininstnid>              <bic>abnanl2a</bic>         </fininstnid>     </dbtragt>     <chrgbr>slev</chrgbr>     <cdttrftxinf>         <pmtid>             <endtoendid>pay003-563585</endtoendid>         </pmtid>     etc..... 

thank in advance input. richard

the attributes of xml input's document tag broken, should check that.

i have no idea why write xml header manually, shouldn't think of such beast. every xslt processor adds automatically if set output format xml.

i used following, simplified xml:

<?xml version="1.0" encoding="utf-8"?> <document xmlns:xsi="http://www.w3.org/2001/xmlschema-instance">   <cstmrcdttrfinitn>     <pmtinf>       <dbtragt>         <fininstnid>           <bic>abnanl2a</bic>         </fininstnid>       </dbtragt>     </pmtinf>   </cstmrcdttrfinitn> </document> 

and xslt stylesheet:

<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform">   <xsl:output method="xml" indent="yes"/>    <xsl:template match="/">     <xsl:apply-templates select="document/cstmrcdttrfinitn/pmtinf/dbtragt"/>   </xsl:template>    <xsl:template match="dbtragt">     <othr>       <id>notprovided</id>     </othr>   </xsl:template>  </xsl:stylesheet> 

output:

<?xml version="1.0" encoding="utf-8"?> <othr>   <id>notprovided</id> </othr> 

this how xslt supposed used, it's pattern matching , functional programming.


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -