Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with xsl sort Please.

Status
Not open for further replies.

MathGeek78

Programmer
Dec 18, 2009
1
US

Hi,

I am not exactly sure how the following code is working within the select portion. Can someone please explain this part of the code?

<xsl:sort select="if ($sortColumn1/@numeric = 'true') then number(*[name() = $sortColumn1]) else *[name() = $sortColumn1]" order="{$sortOrder1}"/>

Thank You,
Ruben
 
I can summarize the ordering of the sort like this:
[1] It is an xslt 2.0 sort element.
[2] $sortColumn1 is evaluated to an element with a text node child which will be matched with some element name() in the template or for-each construct.
[3] During the matching (either the template select or for-each context nodes, two things happen
[3.1] Either the name() matches up with the text content of $solColumn1;
[3.1.1] In that case, if that element's text content can be converted to number (number() function succeeds), it would be classified into higher-order-index block.
[3.1.2] If the element's text content cannot be converted to number successfully, it would be classified into lower-order-index block.
[3.2] Or the name() does not match up with the text content of the same, then all those elements will be classified into the lower order index block.
[4] Within the higher-order-index block, the elements will be ordered according to the ordering of number, if "numeric" attribute be "true" or according to the order of string (now some language-dependence may come in) if "number" attribute be anything other than "true".
[5] Within the lower-order-index block, the elements will be ordered according to the document order or no sort at all: here a bit of implementation dependence may come in.
[6] The final order will be following the $sortOrder, which must take on the value of either ascending or descending: either from lower-order to higher-order for "ascending" or from higher-order to lower-order for "descending".
[7] Clear? As mud?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top