Sort based on attribute values
Posted: Mon Oct 17, 2005 5:51 pm
Hi everybody
I have a problem to sort my xml document. I would like to sort the document based on the attribute value of the attribute "Code department". What is the problem?
I can create an new document but it is empty.
XML-Document:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="styles.xslt"?>
<Request xmlns="newsalesorder">
<Parameters Method="NewSalesOrder">
<Order Service="0" DocumentType="Order">
<OrderFields>
<Field Name="Sell-to Customer No.">150649</Field>
<Field Name="Your Reference">TEST</Field>
<Field Name="External Document No.">20050514</Field>
</OrderFields>
<Lines>
<LineFields Type="Item">
<Field Name="No.">273080</Field>
<Field Name="Quantity">1</Field>
<Field Name="Code Department">2</Field>
</LineFields>
</Lines>
<Lines>
<LineFields Type="Item">
<Field Name="No.">273081</Field>
<Field Name="Quantity">1</Field>
<Field Name="Code Department">1</Field>
</LineFields>
</Lines>
</Order>
</Parameters>
</Request>
XSLT-Document:
<?xml version="1.0" encoding="UTF-8"?>
<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:template match="/">
<xsl:apply-templates select="Request/Parameters/Order/Lines/LineFields/Field">
<xsl:sort select="Field/@Name = Code Department" order="ascending" />
</xsl:apply-templates>
</xsl:template>
</xsl:stylesheet>
Thanks a lot for your help.
Greetings Iwan
I have a problem to sort my xml document. I would like to sort the document based on the attribute value of the attribute "Code department". What is the problem?
I can create an new document but it is empty.
XML-Document:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="styles.xslt"?>
<Request xmlns="newsalesorder">
<Parameters Method="NewSalesOrder">
<Order Service="0" DocumentType="Order">
<OrderFields>
<Field Name="Sell-to Customer No.">150649</Field>
<Field Name="Your Reference">TEST</Field>
<Field Name="External Document No.">20050514</Field>
</OrderFields>
<Lines>
<LineFields Type="Item">
<Field Name="No.">273080</Field>
<Field Name="Quantity">1</Field>
<Field Name="Code Department">2</Field>
</LineFields>
</Lines>
<Lines>
<LineFields Type="Item">
<Field Name="No.">273081</Field>
<Field Name="Quantity">1</Field>
<Field Name="Code Department">1</Field>
</LineFields>
</Lines>
</Order>
</Parameters>
</Request>
XSLT-Document:
<?xml version="1.0" encoding="UTF-8"?>
<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:template match="/">
<xsl:apply-templates select="Request/Parameters/Order/Lines/LineFields/Field">
<xsl:sort select="Field/@Name = Code Department" order="ascending" />
</xsl:apply-templates>
</xsl:template>
</xsl:stylesheet>
Thanks a lot for your help.
Greetings Iwan