[xsl] how to sort a list of xpaths

Subject: [xsl] how to sort a list of xpaths
From: Mark Hutchinson <mark@xxxxxxxxxxx>
Date: Sat, 19 Jan 2008 23:10:35 -0800
I have an application that uses xpaths to identify which rule that
should be executed for a given tag in a source file.

eg given a source file of:
<section>
   <class type="AA">
      <entry>entry text</para>
   </class>
   <class type="BB">
      <entry type="italic">text text</para>
      <entry>text text</entry>
      <class>
         <entry>subclass entry text</entry>
      </class>
   </class>
</section>

My application might have the following rules :

  1. /section/class[@type="AA"]/entry
  2. //class
  3. /section/class[@type="BB"]/entry
  4. //entry
  5. //entry[@type="italic"]

My application searches the rules from the top down - stopping from
checking any further once a match has been found. ie the first class
(AA) matches with rule 1 and this is correct. The second class (BB)
matches with rule 2 which is, obviously, not correct.

Here's my question (finally!) - do anyone have a utility or xslt, perl
etc that can sort these rules based on a schema?

Regards
Mark H.

Current Thread