0

I need to convert a XML using a XSLT mapping and I have no idea how to do this...... can you help me

My source XML :

    <?xml version="1.0" encoding="UTF-8"?>
<order-header>
    <id type="integer">1</id>
    <created-at type="dateTime">2020-01-25T18:59:02-03:00</created-at>
    <updated-at type="dateTime">2020-04-23T15:28:13-03:00</updated-at>
    <po-number>1</po-number>
    <price-hidden type="boolean">false</price-hidden>
    <acknowledged-flag type="boolean">false</acknowledged-flag>
    <acknowledged-at nil="true"/>
    <status>issued</status>
    <transmission-status>sent_via_email</transmission-status>
    <version type="integer">1</version>
    <internal-revision type="integer">3</internal-revision>
    <exported type="boolean">false</exported>
    <last-exported-at nil="true"/>
    <payment-method>invoice</payment-method>
    <ship-to-attention>10422282000179</ship-to-attention>
    <coupa-accelerate-status nil="true"/>
    <change-type>revision</change-type>
    <transmission-method-override>supplier_default</transmission-method-override>
    <transmission-emails></transmission-emails>
</order-header>

And I need this result:

<?xml version="1.0" encoding="UTF_8"?>
<ns0:MT_CRIAALTSAP_RES xmlns:ns0="urn:xxxx:xxxxxx">
<order_header>
    <id type="integer">1</id>
    <created_at type="dateTime">2020-01-25T18:59:02-03:00</created_at>
    <updated_at type="dateTime">2020-04-23T15:28:13-03:00</updated_at>
    <po_number>1</po_number>
    <price_hidden type="boolean">false</price_hidden>
    <acknowledged_flag type="boolean">false</acknowledged_flag>
    <acknowledged_at nil="true"/>
    <status>issued</status>
    <transmission_status>sent_via_email</transmission_status>
    <version type="integer">1</version>
    <internal_revision type="integer">3</internal_revision>
    <exported type="boolean">false</exported>
    <last_exported_at nil="true"/>
    <payment_method>invoice</payment_method>
    <ship_to_attention>10422282000179</ship_to_attention>
    <coupa_accelerate_status nil="true"/>
    <change_type>revision</change_type>
    <transmission_method_override>supplier_default</transmission_method_override>
    <transmission_emails></transmission_emails>
</order_header>
</ns0:MT_CRIAALTSAP_RES>

I'm using this code below, code that I taked in the forum :

<?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" version="1.0">


    <xsl:output method="xml" indent="yes"/>


    <xsl:template match="*[contains(local-name(.), '-')]">
            <xsl:element name="{translate(local-name(),'-','_')}">
                <xsl:copy-of select="@*"/>
                <xsl:apply-templates/>

            </xsl:element>

    </xsl:template>


    <xsl:template match="@* | node()">
        <xsl:copy>
            <xsl:apply-templates select="@* | node()"/>
        </xsl:copy>
    </xsl:template>
    
</xsl:stylesheet>

The code works fine but I need the root element as <ns0:MT_CRIAALTSAP_RES xmlns:ns0="urn:xxxx:xxxxxx">

Could you help me with this issue?

1 Answer 1

2

Add a template with match="/" which creates the root element you want as a literal result element and inside does <xsl:apply-templates/>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.