0

I am not an expert in XSLT and require help. We are pulling AWB status from ecomm express logistics. The xml structure they are providing the data is in django serialized xml format. We want to select only the required data from this xml. Tried to extract the attribute name and its value but it's not giving the desired output.

Below is the input structure

<ecomexpress-objects version="1.0">
    <object pk="1" model="awb">
    <field type="BigIntegerField" name="awb_number">700054480</field>
    <field type="CharField" name="orderid">5012</field>
    <field type="FloatField" name="actual_weight">0.5</field>
    <field type="CharField" name="origin">DELHI-DSW</field>
    <field type="CharField" name="destination">DELHI-DLN</field>
    <field type="CharField" name="customer">Ecom Express Private Limited - 32012</field>
    <field type="CharField" name="consignee">MUKESH KUMAR GUPTA</field>
    <field type="CharField" name="pickupdate">11-Feb-2013</field>
    <field type="CharField" name="status">Delivered / Closed</field>
    <field type="CharField" name="reason_code"/>
    <field type="CharField" name="reason_code_description"/>
    <field type="CharField" name="reason_code_number">999</field>
    <field type="CharField" name="receiver">mukesh 9999488339</field>
    <field type="CharField" name="expected_date">12-Feb-2013</field>
    <field type="CharField" name="last_update_date">05-Apr-2013</field>
    <field type="CharField" name="delivery_date">2013-02-17 11:26:00</field>
    <field type="CharField" name="ref_awb">None</field>
    <field type="CharField" name="rts_shipment"/>
    <field type="CharField" name="system_delivery_update">2013-02-17 11:26:00</field>
    <field type="CharField" name="rts_system_delivery_status"/>
    </object>
<object pk="2" model="awb">
    <field type="BigIntegerField" name="awb_number">700054482</field>
    <field type="CharField" name="orderid">5014</field>
    <field type="FloatField" name="actual_weight">0.5</field>
    <field type="CharField" name="origin">DELHI-DSW</field>
    <field type="CharField" name="destination">DELHI-DLN</field>
    <field type="CharField" name="customer">Ecom Express Private Limited - 32012</field>
    <field type="CharField" name="consignee">MUKESH KUMAR GUPTA</field>
    <field type="CharField" name="pickupdate">11-Feb-2013</field>
    <field type="CharField" name="status">Delivered / Closed</field>
    <field type="CharField" name="reason_code"/>
    <field type="CharField" name="reason_code_description"/>
    <field type="CharField" name="reason_code_number">999</field>
    <field type="CharField" name="receiver">mukesh 9999488339</field>
    <field type="CharField" name="expected_date">12-Feb-2013</field>
    <field type="CharField" name="last_update_date">05-Apr-2013</field>
    <field type="CharField" name="delivery_date">2013-02-17 11:26:00</field>
    <field type="CharField" name="ref_awb">None</field>
    <field type="CharField" name="rts_shipment"/>
    <field type="CharField" name="system_delivery_update">2013-02-17 11:26:00</field>
    <field type="CharField" name="rts_system_delivery_status"/>
    </object>
 </ecomexpress-objects>

Expected output structure is

<ecommexpress>
<awb>
<awb_number>700054480</awb_number>
<orderid>5012</orderid>
.
.
.
.
.
</awb>
<awb>
<awb_number>700054482</awb_number>
<orderid>5014</orderid>
.
.
.
.
.
</awb>
</ecommexpress>

Multiple times AWB Number could come. So nested structure is expected.

Only XSLT 1.0 is accepted in my system. Please help.

Regards,

Siji Anup

1 Answer 1

1

Use below code

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="xs"
    version="1.0">
    
    <xsl:template match="ecomexpress-objects">
        <ecommexpress><xsl:apply-templates/></ecommexpress>
    </xsl:template>
    
    <xsl:template match="object[@model = 'awb']">
        <awb><xsl:apply-templates/></awb>
    </xsl:template>
    
    <xsl:template match="field[@name]">
        <xsl:element name="{@name}"><xsl:apply-templates/></xsl:element>
    </xsl:template>
    
</xsl:stylesheet>

see transformation at https://xsltfiddle.liberty-development.net/jxDjina

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.