我不是XSLT专家,需要帮助。我们正在取消电子商务快递物流的AWB状态。他们为数据提供的xml结构是django序列化的xml格式。我们只想从这个xml中选择所需的数据。尝试提取属性名称及其值,但没有给出所需的输出。
以下是输入结构
<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>
预期输出结构为
<ecommexpress>
<awb>
<awb_number>700054480</awb_number>
<orderid>5012</orderid>
.
.
.
.
.
</awb>
<awb>
<awb_number>700054482</awb_number>
<orderid>5014</orderid>
.
.
.
.
.
</awb>
</ecommexpress>
AWB号码可能会多次出现。所以嵌套结构是意料之中的事。
我的系统只接受XSLT1.0。请帮忙。
问候,
四季安普
使用以下代码
<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>
请参阅上的转换https://xsltfiddle.liberty-development.net/jxDjina