xml - Copy parallel element as child element of another element -


<?xml version="1.0" encoding="utf-8"?> <root>    <order orderid="12345">       <cartid>12346</cartid>    </order>    <orderpayment paymentid="1234">       <debitcardpayment>          <chargeamount currencycode="usd">22.20</chargeamount>          <debitcard>             <pin>1234</pin>                          </debitcard>       </debitcardpayment>    </orderpayment> </root> 

i have input xml above.i need move orderpayment element in order.i wrote follows

<xsl:template match="v1:order">          <xsl:apply-templates select="v1:root/v1:orderpayment"/>         <xsl:apply-templates select="@*|node()"/>                  </xsl:template>         <xsl:template match="v1:orderpayment">                  <xsl:apply-templates select="@*|node()"/>       </xsl:template>      <xsl:template match="@*|node()">         <xsl:choose>             <xsl:when test=".='' , count(@*)=0">                 <xsl:apply-templates select="@*|node()"/>             </xsl:when>             <xsl:otherwise>                 <xsl:copy>                     <xsl:apply-templates select="@*|node()"/>                 </xsl:copy>             </xsl:otherwise>         </xsl:choose>     </xsl:template>  

output

<order>   .....  <orderpayment>    ..... </orderpayment> </order> 

i not getting expected output.what mistake?

thanks in advance...

given input, following stylesheet:

xslt 1.0

<xsl:stylesheet version="1.0"  xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/> <xsl:strip-space elements="*"/>  <!-- identity transform --> <xsl:template match="@*|node()">     <xsl:copy>         <xsl:apply-templates select="@*|node()"/>     </xsl:copy> </xsl:template>  <xsl:template match="order">     <xsl:copy>         <xsl:apply-templates select="@*|node()"/>         <xsl:copy-of select="../orderpayment"/>     </xsl:copy> </xsl:template>  <xsl:template match="orderpayment"/>  </xsl:stylesheet> 

will return:

<?xml version="1.0" encoding="utf-8"?> <root>    <order orderid="12345">       <cartid>12346</cartid>       <orderpayment paymentid="1234">          <debitcardpayment>             <chargeamount currencycode="usd">22.20</chargeamount>             <debitcard>                <pin>1234</pin>             </debitcard>          </debitcardpayment>       </orderpayment>    </order> </root> 

Comments

Popular posts from this blog

android - Pass an Serializable object in AIDL -

How to provide Authorization & Authentication using Asp.net, C#? -

How to use Authorization & Authentication in Asp.net, C#? -