0

Hello

I have an XML file that uses <Document Element>

I was wondering if it is possible to sort my XML file by sortOrder?

Here is an example of my code:

<?xml version="1.0" standalone="yes"?>
<DocumentElement>
  <Item DataField="A03" Header="RDAW TEST" UseDefaults="Yes" SortOrder="1"/>
  <Item DataField="A01" Header="Eg: Assignment 1" UseDefaults="Yes" SortOrder="2" />
  <Item DataField="A04" Header="RDAW TEST #2" UseDefaults="No" SortOrder="4" />
  <Item DataField="A02" Header="Eg: Assignment 2" UseDefaults="No" SortOrder="3" />
</DocumentElement>

I just want SortOrder to be sorted ascending when you view the XML file.

Thanks

2
Contributors
7
Replies
8
Views
6 Years
Discussion Span
Last Post by pritaeas
0

If you use an xslt to transform it, then you can use xsl:sort. This link shows how.

Thank you i'll look into this.

Does it still work for my XML file as it's <DocumentElement> and then Items?

Just the XML file they are using as an example is slighlty different.

Thanks

0

Hello, i've tried it now but can't seem to get it working.

My XML code:

<?xml-stylesheet type="text/xsl" href="Y10_CCF_SPORT.xsl" version="1.0" standalone="yes"?>
<DocumentElement>
  <Item DataField="A03" Header="RDAW TEST" UseDefaults="Yes" SortOrder="1"/>
  <Item DataField="A01" Header="Eg: Assignment 1" UseDefaults="Yes" SortOrder="2" />
  <Item DataField="A04" Header="RDAW TEST #2" UseDefaults="No" SortOrder="4" />
  <Item DataField="A02" Header="Eg: Assignment 2" UseDefaults="No" SortOrder="3" />
</DocumentElement>

My XSL code:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     version="1.0">

  <xsl:output method="text"/>

  <xsl:template match="DocumentElement">
    <xsl:apply-templates>
      <xsl:sort select="SortOrder"/>
    </xsl:apply-templates>
  </xsl:template>

</xsl:stylesheet>
0

I've tried @SortOrder but still no luck it's just blank when I open the XML document?

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     version="1.0">

  <xsl:output method="text"/>

  <xsl:template match="DocumentElement">
    <xsl:apply-templates>
      <xsl:sort select="@SortOrder"/>
    </xsl:apply-templates>
  </xsl:template>

</xsl:stylesheet>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.