XSLT sorting help / not working for me
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 1
- Joined: Wed Nov 10, 2021 6:54 pm
XSLT sorting help / not working for me
Post by victor_alpha »
Hi All,
So, I have an XML like below -
I need to sort all the ExtnLocationInfo elements inside ShipmentLine tag in ascending order of attribute value FloorLocation.
So Output should be like below
I am trying something like below :
But it is not sorting for me. Please let me know what I am doing wrong. I am really new to this.
So, I have an XML like below -
Code: Select all
<Shipments>
<Shipment CarrierServiceCode="Ground" DeliveryMethod="SHP" ExpectedShipmentDate="2021-10-18T16:43:48+00:00" StatusDate="2021-10-18T16:43:57+00:00">
<Extn ExtnSLAExpectedShipDate="2021-10-19T16:43:48+00:00"/>
<ShipmentLines TotalNumberOfRecords="5">
<ShipmentLine >
<Extn>
<ExtnLocationInfoList>
<ExtnLocationInfo FloorLocation="15NDAR" FloorLocationDesc="Needle Arts"/>
</ExtnLocationInfoList>
</Extn>
</ShipmentLine>
<ShipmentLine >
<Extn>
<ExtnLocationInfoList>
<ExtnLocationInfo FloorLocation="10SWCN" FloorLocationDesc="Sewing Construction"/>
</ExtnLocationInfoList>
</Extn>
</ShipmentLine>
<ShipmentLine >
<Extn>
<ExtnLocationInfoList>
<ExtnLocationInfo FloorLocation="15NDAR" FloorLocationDesc="Needle Arts"/>
</ExtnLocationInfoList>
</Extn>
</ShipmentLine>
<ShipmentLine >
<Extn>
<ExtnLocationInfoList>
<ExtnLocationInfo FloorLocation="15NDAR" FloorLocationDesc="Needle Arts"/>
</ExtnLocationInfoList>
</Extn>
</ShipmentLine>
</ShipmentLines>
</Shipment>
</Shipments>
So Output should be like below
Code: Select all
<Shipments>
<Shipment CarrierServiceCode="Ground" DeliveryMethod="SHP" ExpectedShipmentDate="2021-10-18T16:43:48+00:00" StatusDate="2021-10-18T16:43:57+00:00">
<Extn ExtnSLAExpectedShipDate="2021-10-19T16:43:48+00:00"/>
<ShipmentLines TotalNumberOfRecords="5">
<ShipmentLine>
<Extn>
<ExtnLocationInfoList>
<ExtnLocationInfo FloorLocation="10SWCN" FloorLocationDesc="Sewing Construction"/>
</ExtnLocationInfoList>
</Extn>
</ShipmentLine>
<ShipmentLine>
<Extn>
<ExtnLocationInfoList>
<ExtnLocationInfo FloorLocation="15NDAR" FloorLocationDesc="Needle Arts"/>
</ExtnLocationInfoList>
</Extn>
</ShipmentLine>
<ShipmentLine>
<Extn>
<ExtnLocationInfoList>
<ExtnLocationInfo FloorLocation="15NDAR" FloorLocationDesc="Needle Arts"/>
</ExtnLocationInfoList>
</Extn>
</ShipmentLine>
<ShipmentLine>
<Extn>
<ExtnLocationInfoList>
<ExtnLocationInfo FloorLocation="15NDAR" FloorLocationDesc="Needle Arts"/>
</ExtnLocationInfoList>
</Extn>
</ShipmentLine>
</ShipmentLines>
</Shipment>
</Shipments>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/Shipments/Shipment/*">
<xsl:copy>
<xsl:apply-templates>
<xsl:sort data-type="text" select="/Shipments/Shipment/ShipmentLines/Extn/ExtnLocationInfoList/ExtnLocationInfo/@FloorLocation"
order="ascending" />
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ Artificial Intelligence (AI Positron Assistant add-on)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service