XSL: How can I sort a three digit, hyphen separated value?

Morley Tooke

Problem

I'm trying to sort on the entire value of rule/@id where the value of @id is a three value, hyphenated string like this "1-10-12" or "10-15-2". I've tried converting to a number, and I've tried formatting the number, but no luck.

The code sample output sorts by the left-most digits only, the sub-values are out of order.

XML source:

<rule-mapping name="C">
   <rule id="0-1-1">
      <checker id="checker1"/>
      <checker id="checker2"/>
  </rule>
   <rule id="0-1-10">
      <checker id="checker3"/>
  </rule>
   <rule id="0-1-11">
      <checker id="checker4"/>         
  </rule>
   <rule id="15-1-2">
      <checker id="checker5"/>         
  </rule>
   <rule id="0-1-12">
      <checker id="checker6"/>         
  </rule>
</rule-mapping>

transform snippet:

<tbody>
    <xsl:for-each select="rule-mapping/rule">
        <xsl:sort select="substring-before(@id, '-')" data-type="number"/>
        <xsl:sort select="substring-after(@id, '-')" data-type="number"/>

            <row>
              <entry>
                 <xsl:value-of select="@id"/>                                                                   
              </entry>
              <entry>
              <xsl:for-each select="checker">
                <p>
                 <codeph><xsl:value-of select="@id"/></codeph><xsl:text>&#160;</xsl:text>

                </p>
              </xsl:for-each>                                     
              </entry>                                  
            </row>                          
            <xsl:text>&#xA;</xsl:text>
    </xsl:for-each>
</tbody>

Expected output:

    <row>
       <entry>0-1-1</entry>
       <entry>
         <p><codeph>checker1</codeph> </p>
         <p><codeph>checker2</codeph> </p>
       </entry>
    </row>
    <row>
       <entry>0-1-10</entry>
       <entry>
         <p>
          <codeph>checker3</codeph> </p>
       </entry>
    </row>
    <row>
       <entry>0-1-11</entry>
       <entry>
         <p>
          <codeph>checker4</codeph> </p>
       </entry>
    </row>
    <row>
       <entry>0-1-12</entry>
       <entry>
         <p>
          <codeph>checker6</codeph> </p>
       </entry>
    </row>
    <row>
       <entry>15-1-2</entry>
       <entry>
         <p>
          <codeph>checker5</codeph> </p>
       </entry>
    </row>

Thanks in advance.

JLRishe

You have the right idea, but you need to take it one step further:

<xsl:sort select="substring-before(@id, '-')" data-type="number"/>
<xsl:sort select="substring-before(substring-after(@id, '-'), '-')" data-type="number"/>
<xsl:sort select="substring-after(substring-after(@id, '-'), '-')" data-type="number"/>

With those three xsl:sorts together, it should sort the way you want.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I get tag's text value with xsl transformation

From Dev

How can I define a task named with a hyphen?

From Dev

How can I sort by a calculated value in elasticsearch

From Dev

How to sort within array separated by Key with comma separated value

From Dev

How can I sort (Custom Sort) list of Dictionary entry by value

From Dev

How to sort a text file with three columns, each separated by a comma?

From Dev

How to make the controller's name hyphen "-" separated?

From Dev

How to convert arrayList to string separated by hyphen

From Dev

How to convert arrayList to string separated by hyphen

From Dev

How can I sum the second digit to the last digit in an integer on java?

From Dev

how can i get single digit from four digit

From Dev

How Can I Test Whether a Variable Contains an Element Value or a String / Number Value? (XSL 1.0)

From Dev

How do i replace a value displayed 0.00 to '-' hyphen in Visualbasic 6.0

From Dev

How can I break numbers into their digit values?

From Dev

How can I sort these?

From Dev

How can I replace hyphen "cells" in R data frames with zeros?

From Dev

Codeigniter URI Class how can i use – hyphen instead _ underscore?

From Dev

How can I split hyphen-containing words using sed?

From Dev

How can I sort a std::map first by value, then by key?

From Dev

How can I sort a Guava Multiset on entry value and count?

From Dev

How can I sort this array of arrays by the second value in each array?

From Dev

PHP - How can I sort this multi dimensional array by sum value?

From Dev

How can I sort an array of objects in an array by string value?

From Dev

How Can I Sort the [Array] Value Elements in Angularjs?

From Dev

How can I sort datetime columns by row value in a Pandas dataframe?

From Dev

how to i fomat 4 digit in Arrays.sort(java)

From Dev

How to Sort Dates in XSL?

From Java

How can I find the full dot-separated key when searching a nested object via the value?

From Dev

How can I create linked tags from a comma separated list value in Stacey App?

Related Related

  1. 1

    How can I get tag's text value with xsl transformation

  2. 2

    How can I define a task named with a hyphen?

  3. 3

    How can I sort by a calculated value in elasticsearch

  4. 4

    How to sort within array separated by Key with comma separated value

  5. 5

    How can I sort (Custom Sort) list of Dictionary entry by value

  6. 6

    How to sort a text file with three columns, each separated by a comma?

  7. 7

    How to make the controller's name hyphen "-" separated?

  8. 8

    How to convert arrayList to string separated by hyphen

  9. 9

    How to convert arrayList to string separated by hyphen

  10. 10

    How can I sum the second digit to the last digit in an integer on java?

  11. 11

    how can i get single digit from four digit

  12. 12

    How Can I Test Whether a Variable Contains an Element Value or a String / Number Value? (XSL 1.0)

  13. 13

    How do i replace a value displayed 0.00 to '-' hyphen in Visualbasic 6.0

  14. 14

    How can I break numbers into their digit values?

  15. 15

    How can I sort these?

  16. 16

    How can I replace hyphen "cells" in R data frames with zeros?

  17. 17

    Codeigniter URI Class how can i use – hyphen instead _ underscore?

  18. 18

    How can I split hyphen-containing words using sed?

  19. 19

    How can I sort a std::map first by value, then by key?

  20. 20

    How can I sort a Guava Multiset on entry value and count?

  21. 21

    How can I sort this array of arrays by the second value in each array?

  22. 22

    PHP - How can I sort this multi dimensional array by sum value?

  23. 23

    How can I sort an array of objects in an array by string value?

  24. 24

    How Can I Sort the [Array] Value Elements in Angularjs?

  25. 25

    How can I sort datetime columns by row value in a Pandas dataframe?

  26. 26

    how to i fomat 4 digit in Arrays.sort(java)

  27. 27

    How to Sort Dates in XSL?

  28. 28

    How can I find the full dot-separated key when searching a nested object via the value?

  29. 29

    How can I create linked tags from a comma separated list value in Stacey App?

HotTag

Archive