Create XSLT for copy of entire XML but update few tags with static value -


i want create xslt copying same input xml want change few xml tags static value.

i had tried self building xslt, can see output xml same input xml.

here input xml file

<?xml version="1.0" encoding="utf-8"?> <document   xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"   xmlns:xsd="http://www.w3.org/2001/xmlschema"   systemversion="7.00.3.71.03"   system="hubbroker"   version="101"   xmlns="http://rep.evenex.dk/schema/evenex/ebusiness_01">   <header>     <senderendpointid qualifier="cvr">00000000</senderendpointid>     <receiverendpointid qualifier="ean">6564654656546</receiverendpointid>     <createddate>2016-04-07</createddate>     <createdtime>12:25:59</createdtime>     <edirefno>24721</edirefno>     <test>false</test>     <acknowledgementrequest>yes</acknowledgementrequest>     <mailbounce>false</mailbounce>     <agreementno>0000</agreementno>     <internalmessage>false</internalmessage>   </header>   <body>     <originalreceiverendpointid>0000</originalreceiverendpointid>     <referenceddocumenttype>invoic</referenceddocumenttype>     <dispatchreference>28373</dispatchreference>     <documenttype>invoic</documenttype>     <documentno>24721</documentno>     <receiptstatus>false</receiptstatus>     <responseindicator>12</responseindicator>     <referencedinvoiceno />     <referencedcreditnoteno />     <documentdate>2016-04-07</documentdate>     <startdatecatalogue>2016-04-07</startdatecatalogue>     <enddatecatalogue>2016-04-07</enddatecatalogue>     <shipmentdate>2016-04-07</shipmentdate>     <duedate>2016-05-30</duedate>     <invoicedate>2016-04-07</invoicedate>     <pmtdiscountdate>2016-04-07</pmtdiscountdate>     <requesteddeliverydate>2016-04-07</requesteddeliverydate>     <promiseddeliverydate>2016-04-07</promiseddeliverydate>     <promiseddeliverytime>00:00:00</promiseddeliverytime>     <orderdate>2016-04-07</orderdate>     <quoteno>0000</quoteno>     <campaignno>0000</campaignno>     <accountcode>kontooverfØrsel</accountcode>     <orderno>po5101903</orderno>     <bankname>danske bank</bankname>     <bankbranchno>4394</bankbranchno>     <bankaccountno>4795026355</bankaccountno>     <iban />     <swift />     <paymenttype />     <paymentid>4795026355</paymentid>     <paymentvendorno />     <paymenttermscode>kontooverfØrsel</paymenttermscode>     <currencycode>dkk</currencycode>     <shipmentno>28373</shipmentno>     <contractno>0000</contractno>     <pricelistno>0000</pricelistno>     <externaldocumentno>po5101903</externaldocumentno>     <payableamount>9756.25</payableamount>     <taxableamount>7805.00</taxableamount>     <taxamount>1951.25</taxamount>     <taxinclusiveamount>9756.25</taxinclusiveamount>     <totalitemamount>7805.00</totalitemamount>     <totaldiscountamount>0</totaldiscountamount>     <totalchargeamount>0</totalchargeamount>     <paymentdiscountpercent>0.0</paymentdiscountpercent>     <nettotal>0.0</nettotal>     <shipmentmethodcode>ablager</shipmentmethodcode>     <seasontext>0000</seasontext>     <collection>0000</collection>     <cataloguefunctioncode>9</cataloguefunctioncode>     <comments>       <comment>disp.: h914hje</comment>     </comments>     <freetext>       <text no="del">         <textstring>disp.: h914hje</textstring>       </text>     </freetext>     <references>       <ref type="on">         <reference>po5101903</reference>       </ref>     </references>     <yourreference />     <rounding>0.0</rounding>     <collectiondate>2016-04-07</collectiondate>     <collectiontime>00:00:00</collectiontime>     <loadindicator>2</loadindicator>     <transportpriority>3</transportpriority>     <transportrefno />     <transportpmtindicator />     <transportmethodcode>1</transportmethodcode>     <charges>       <charge type="freight">         <amount>0.00</amount>         <taxcategory>s</taxcategory>         <taxamount>0.0</taxamount>         <percent>0.0</percent>       </charge>     </charges>     <allowances>       <allowance type="standard">         <amount>0.00</amount>         <taxcategory>s</taxcategory>         <taxamount>0.0</taxamount>         <percent>0.0</percent>       </allowance>     </allowances>     <exciseduties>       <exciseduty type="9">         <amount>0.0</amount>         <taxcategory>s</taxcategory>         <taxamount>0.0</taxamount>         <percent>0.0</percent>       </exciseduty>     </exciseduties>     <invoicediscounts>       <invoicediscount discounttype="3">         <discountperiodunit>day</discountperiodunit>         <discountperiod />         <discountpercent />       </invoicediscount>     </invoicediscounts>     <parties>       <party type="billto">         <no>6564654656546</no>       </party>       <party type="sellto">         <no>6564654656546</no>         <name>denmark danmark a/s</name>         <name2 />         <postbox />         <address>anelystparken 16</address>         <address2 />         <buildingnumber />         <city>mundelstrup</city>         <postcode>8381</postcode>         <countryregioncode>dk</countryregioncode>         <county />         <contactrole />         <vatregno />         <contact>ikke angivet</contact>         <contactphoneno />         <contactfaxno />         <contactemail />         <suppliernobycustomer />       </party>       <party type="supplier">         <no>00000000</no>         <name>asd asd a/s</name>         <name2 />         <postbox />         <address>gejlhavegård 17</address>         <address2 />         <buildingnumber />         <city>kolding</city>         <postcode>6000</postcode>         <countryregioncode>dk</countryregioncode>         <county />         <contactrole />         <vatregno>           dk00000000         </vatregno>         <contact />         <contactphoneno />         <contactfaxno />         <contactemail />         <suppliernobycustomer />       </party>       <party type="shipto">         <no>19555305</no>         <name />         <name2 />         <postbox />         <address>           denmark hjørring           frederikshavnsvej 290         </address>         <address2 />         <buildingnumber />         <city>hjørring</city>         <postcode>9800</postcode>         <countryregioncode>dk</countryregioncode>         <county />         <contactrole />         <vatregno />         <contact />         <contactphoneno />         <contactfaxno />         <contactemail />         <suppliernobycustomer />       </party>     </parties>     <taxsubtotals>       <taxsubtotal type="s">         <taxableamount>7805.00</taxableamount>         <taxamount>1951.25</taxamount>         <taxcategory>           <id>s</id>           <percent>25.00</percent>           <taxscheme>             <id>vat</id>           </taxscheme>         </taxcategory>       </taxsubtotal>     </taxsubtotals>     <lines>       <line>         <lineno>1</lineno>         <linerefno>1</linerefno>         <eanno>0200100218620</eanno>         <itemno>ol 0308 b</itemno>         <requestnotification>3</requestnotification>         <sublinereference>1</sublinereference>         <requesteddeliverydate>2016-04-07</requesteddeliverydate>         <promiseddeliverydate>2016-04-07</promiseddeliverydate>         <planneddeliverydate>2016-04-07</planneddeliverydate>         <plannedshipmentdate>2016-04-07</plannedshipmentdate>         <shipmentdate>2016-04-07</shipmentdate>         <earliestdeliverydate>2016-04-07</earliestdeliverydate>         <latestdeliverydate>2016-04-07</latestdeliverydate>         <expirydate>2016-04-07</expirydate>         <description>stålvask 400 x 340 mm</description>         <grossweight>0</grossweight>         <netweight>0</netweight>         <packettype>box</packettype>         <unitsperparcel>0</unitsperparcel>         <unitvolume>0</unitvolume>         <unitcost>0</unitcost>         <quantity>5.00</quantity>         <outstandingquantity>0</outstandingquantity>         <quantityshipped>0</quantityshipped>         <minimumquantity>0</minimumquantity>         <creditedquantity>0</creditedquantity>         <quantityinvoiced>5.00</quantityinvoiced>         <unitofmeasure>pce</unitofmeasure>         <unitprice>198.00</unitprice>         <netunitprice>198.00</netunitprice>         <amount>990.00</amount>         <amountincludingvat>1237.50</amountincludingvat>         <lineextensionamount>990.00</lineextensionamount>         <invdiscamounttoinvoice>0</invdiscamounttoinvoice>         <retailprice>0</retailprice>         <taxsubtotals>           <taxsubtotal type="s">             <taxableamount>990.00</taxableamount>             <taxamount>247.50</taxamount>             <taxcategory>               <id>s</id>               <percent>25.00</percent>               <taxscheme>                 <id>vat</id>               </taxscheme>             </taxcategory>           </taxsubtotal>         </taxsubtotals>         <linediscountpct>0</linediscountpct>         <linediscountamount>0.00</linediscountamount>       </line>     </lines>   </body> </document> 

i want generate same output file few tags updated static value.

here xslt code tried make,

<?xml version="1.0"?> <xsl:stylesheet version="1.0"   xmlns:xsl    = "http://www.w3.org/1999/xsl/transform"     xmlns:xsi    = "http://www.w3.org/2001/xmlschema-instance"   xmlns="http://rep.evenex.dk/schema/evenex/ebusiness_01">     <xsl:strip-space elements="*"/>   <xsl:output method="xml" indent="yes"/>   <xsl:template match="header">     <xsl:copy>       <xsl:apply-templates select="@*|node()"/>       <xsl:element name="senderendpointid">11111111</xsl:element>     </xsl:copy>   </xsl:template>     <!--identity template,  provides default behavior copies content output -->   <xsl:template match="@*|node()">     <xsl:copy>       <xsl:apply-templates select="@*|node()"/>     </xsl:copy>   </xsl:template> </xsl:stylesheet> 

i want update senderendpointid in header tag fixed value '11111111'

also <no> , <vatregno> tag inside <party type="supplier"> - rest of tags remain same.

<party type="supplier">    <no>11111111</no>            <vatregno>dk11111111</vatregno>        </party> 

so final output should like

<?xml version="1.0" encoding="utf-8"?> <document   xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"   xmlns:xsd="http://www.w3.org/2001/xmlschema"   systemversion="7.00.3.71.03"   system="hubbroker"   version="101"   xmlns="http://rep.evenex.dk/schema/evenex/ebusiness_01">   <header>     <senderendpointid qualifier="cvr">11111111</senderendpointid>     <receiverendpointid qualifier="ean">6564654656546</receiverendpointid>     <createddate>2016-04-07</createddate>     <createdtime>12:25:59</createdtime>     <edirefno>24721</edirefno>     <test>false</test>     <acknowledgementrequest>yes</acknowledgementrequest>     <mailbounce>false</mailbounce>     <agreementno>0000</agreementno>     <internalmessage>false</internalmessage>   </header>   <body>     <originalreceiverendpointid>0000</originalreceiverendpointid>     <referenceddocumenttype>invoic</referenceddocumenttype>     <dispatchreference>28373</dispatchreference>     <documenttype>invoic</documenttype>     <documentno>24721</documentno>     <receiptstatus>false</receiptstatus>     <responseindicator>12</responseindicator>     <referencedinvoiceno />     <referencedcreditnoteno />     <documentdate>2016-04-07</documentdate>     <startdatecatalogue>2016-04-07</startdatecatalogue>     <enddatecatalogue>2016-04-07</enddatecatalogue>     <shipmentdate>2016-04-07</shipmentdate>     <duedate>2016-05-30</duedate>     <invoicedate>2016-04-07</invoicedate>     <pmtdiscountdate>2016-04-07</pmtdiscountdate>     <requesteddeliverydate>2016-04-07</requesteddeliverydate>     <promiseddeliverydate>2016-04-07</promiseddeliverydate>     <promiseddeliverytime>00:00:00</promiseddeliverytime>     <orderdate>2016-04-07</orderdate>     <quoteno>0000</quoteno>     <campaignno>0000</campaignno>     <accountcode>kontooverfØrsel</accountcode>     <orderno>po5101903</orderno>     <bankname>danske bank</bankname>     <bankbranchno>4394</bankbranchno>     <bankaccountno>4795026355</bankaccountno>     <iban />     <swift />     <paymenttype />     <paymentid>4795026355</paymentid>     <paymentvendorno />     <paymenttermscode>kontooverfØrsel</paymenttermscode>     <currencycode>dkk</currencycode>     <shipmentno>28373</shipmentno>     <contractno>0000</contractno>     <pricelistno>0000</pricelistno>     <externaldocumentno>po5101903</externaldocumentno>     <payableamount>9756.25</payableamount>     <taxableamount>7805.00</taxableamount>     <taxamount>1951.25</taxamount>     <taxinclusiveamount>9756.25</taxinclusiveamount>     <totalitemamount>7805.00</totalitemamount>     <totaldiscountamount>0</totaldiscountamount>     <totalchargeamount>0</totalchargeamount>     <paymentdiscountpercent>0.0</paymentdiscountpercent>     <nettotal>0.0</nettotal>     <shipmentmethodcode>ablager</shipmentmethodcode>     <seasontext>0000</seasontext>     <collection>0000</collection>     <cataloguefunctioncode>9</cataloguefunctioncode>     <comments>       <comment>disp.: h914hje</comment>     </comments>     <freetext>       <text no="del">         <textstring>disp.: h914hje</textstring>       </text>     </freetext>     <references>       <ref type="on">         <reference>po5101903</reference>       </ref>     </references>     <yourreference />     <rounding>0.0</rounding>     <collectiondate>2016-04-07</collectiondate>     <collectiontime>00:00:00</collectiontime>     <loadindicator>2</loadindicator>     <transportpriority>3</transportpriority>     <transportrefno />     <transportpmtindicator />     <transportmethodcode>1</transportmethodcode>     <charges>       <charge type="freight">         <amount>0.00</amount>         <taxcategory>s</taxcategory>         <taxamount>0.0</taxamount>         <percent>0.0</percent>       </charge>     </charges>     <allowances>       <allowance type="standard">         <amount>0.00</amount>         <taxcategory>s</taxcategory>         <taxamount>0.0</taxamount>         <percent>0.0</percent>       </allowance>     </allowances>     <exciseduties>       <exciseduty type="9">         <amount>0.0</amount>         <taxcategory>s</taxcategory>         <taxamount>0.0</taxamount>         <percent>0.0</percent>       </exciseduty>     </exciseduties>     <invoicediscounts>       <invoicediscount discounttype="3">         <discountperiodunit>day</discountperiodunit>         <discountperiod />         <discountpercent />       </invoicediscount>     </invoicediscounts>     <parties>       <party type="billto">         <no>6564654656546</no>       </party>       <party type="sellto">         <no>6564654656546</no>         <name>denmark danmark a/s</name>         <name2 />         <postbox />         <address>anelystparken 16</address>         <address2 />         <buildingnumber />         <city>mundelstrup</city>         <postcode>8381</postcode>         <countryregioncode>dk</countryregioncode>         <county />         <contactrole />         <vatregno />         <contact>ikke angivet</contact>         <contactphoneno />         <contactfaxno />         <contactemail />         <suppliernobycustomer />       </party>       <party type="supplier">         <no>11111111</no>         <name>asd asd a/s</name>         <name2 />         <postbox />         <address>gejlhavegård 17</address>         <address2 />         <buildingnumber />         <city>kolding</city>         <postcode>6000</postcode>         <countryregioncode>dk</countryregioncode>         <county />         <contactrole />         <vatregno>           dk11111111         </vatregno>         <contact />         <contactphoneno />         <contactfaxno />         <contactemail />         <suppliernobycustomer />       </party>       <party type="shipto">         <no>19555305</no>         <name />         <name2 />         <postbox />         <address>           denmark hjørring           frederikshavnsvej 290         </address>         <address2 />         <buildingnumber />         <city>hjørring</city>         <postcode>9800</postcode>         <countryregioncode>dk</countryregioncode>         <county />         <contactrole />         <vatregno />         <contact />         <contactphoneno />         <contactfaxno />         <contactemail />         <suppliernobycustomer />       </party>     </parties>     <taxsubtotals>       <taxsubtotal type="s">         <taxableamount>7805.00</taxableamount>         <taxamount>1951.25</taxamount>         <taxcategory>           <id>s</id>           <percent>25.00</percent>           <taxscheme>             <id>vat</id>           </taxscheme>         </taxcategory>       </taxsubtotal>     </taxsubtotals>     <lines>       <line>         <lineno>1</lineno>         <linerefno>1</linerefno>         <eanno>0200100218620</eanno>         <itemno>ol 0308 b</itemno>         <requestnotification>3</requestnotification>         <sublinereference>1</sublinereference>         <requesteddeliverydate>2016-04-07</requesteddeliverydate>         <promiseddeliverydate>2016-04-07</promiseddeliverydate>         <planneddeliverydate>2016-04-07</planneddeliverydate>         <plannedshipmentdate>2016-04-07</plannedshipmentdate>         <shipmentdate>2016-04-07</shipmentdate>         <earliestdeliverydate>2016-04-07</earliestdeliverydate>         <latestdeliverydate>2016-04-07</latestdeliverydate>         <expirydate>2016-04-07</expirydate>         <description>stålvask 400 x 340 mm</description>         <grossweight>0</grossweight>         <netweight>0</netweight>         <packettype>box</packettype>         <unitsperparcel>0</unitsperparcel>         <unitvolume>0</unitvolume>         <unitcost>0</unitcost>         <quantity>5.00</quantity>         <outstandingquantity>0</outstandingquantity>         <quantityshipped>0</quantityshipped>         <minimumquantity>0</minimumquantity>         <creditedquantity>0</creditedquantity>         <quantityinvoiced>5.00</quantityinvoiced>         <unitofmeasure>pce</unitofmeasure>         <unitprice>198.00</unitprice>         <netunitprice>198.00</netunitprice>         <amount>990.00</amount>         <amountincludingvat>1237.50</amountincludingvat>         <lineextensionamount>990.00</lineextensionamount>         <invdiscamounttoinvoice>0</invdiscamounttoinvoice>         <retailprice>0</retailprice>         <taxsubtotals>           <taxsubtotal type="s">             <taxableamount>990.00</taxableamount>             <taxamount>247.50</taxamount>             <taxcategory>               <id>s</id>               <percent>25.00</percent>               <taxscheme>                 <id>vat</id>               </taxscheme>             </taxcategory>           </taxsubtotal>         </taxsubtotals>         <linediscountpct>0</linediscountpct>         <linediscountamount>0.00</linediscountamount>       </line>     </lines>   </body> </document> 

any appreciated

thanks

if want update senderenpointid in xml, need template matches element. however, need take account namespace.

this because in input xml senderenpointid element in default namespace http://rep.evenex.dk/schema/evenex/ebusiness_01. although have defined default namespace in xslt, won't apply xpath expressions in match attributes.

to handle this, have declare namespace again prefix, , use in xpath expression.

xmlns:e="http://rep.evenex.dk/schema/evenex/ebusiness_01" 

so, template this

  <xsl:template match="e:senderendpointid">      <xsl:copy>         <xsl:apply-templates select="@*|*"/>         <xsl:text>11111111</xsl:text>      </xsl:copy>   </xsl:template>  

alternatively, if wanted update text of senderendpointid, can replace current template matching it, simpler 1 instead:

 <xsl:template match="e:senderendpointid/text()">     <xsl:text>11111111</xsl:text>  </xsl:template>  

you can have similar templates elements under party. example

  <xsl:template match="e:party[@type='supplier']/e:no">       <no>         <xsl:text>11111111</xsl:text>       </no>   </xsl:template> 

or maybe this

  <xsl:template match="e:party[@type='supplier']/e:no/text()">       <xsl:text>11111111</xsl:text>   </xsl:template> 

try this...

<xsl:stylesheet version="1.0"   xmlns:xsl    = "http://www.w3.org/1999/xsl/transform"   xmlns:xsi    = "http://www.w3.org/2001/xmlschema-instance"   xmlns="http://rep.evenex.dk/schema/evenex/ebusiness_01"     xmlns:e="http://rep.evenex.dk/schema/evenex/ebusiness_01">      <xsl:strip-space elements="*"/>    <xsl:output method="xml" indent="yes"/>    <xsl:template match="e:senderendpointid/text()">       <xsl:text>11111111</xsl:text>   </xsl:template>     <xsl:template match="e:party[@type='supplier']/e:no/text()">       <xsl:text>11111111</xsl:text>   </xsl:template>    <xsl:template match="e:party[@type='supplier']/e:vatregno/text()">       <xsl:text>dk11111111</xsl:text>   </xsl:template>    <!--identity template,  provides default behavior copies content output -->   <xsl:template match="@*|node()">     <xsl:copy>       <xsl:apply-templates select="@*|node()"/>     </xsl:copy>   </xsl:template> </xsl:stylesheet> 

note if able use xslt 2.0, make use of xpath-default-namespace set default namespace xpath expressions.


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -