There is xml. I create an Html page from it.

<price> <period cost="1000.0000" type="3" typename="year" length="1">1 год</period> <period cost="99.0000" type="1" typename="month" length="1">1 месяц</period> <period cost="250.0000" type="1" typename="month" length="3">3 месяца</period> <period cost="500.0000" type="1" typename="month" length="6">6 месяцев</period> <period cost="14990.0000" type="0" typename="day" length="" >Бессрочная лицензия</period> </price> 

How to organize sorting for a cycle so that the node goes first 1 month, 2 months ... 1 year .., Perpetual license ?

 <xsl:for-each select="price/period"> <xsl:sort select="???"/> <!--мои действия с нодом --> </xsl:for-each> 

you need to somehow organize the sort function with the condition of something like

mnemonic

 if type = 1 then return length * 30 if type = 3 then return length * 365 if type = 0 then return 1000000 

    1 answer 1

    In my opinion, the easiest way is to sort by price:

     <xsl:for-each select="price/period"> <xsl:sort select="@cost" data-type="number"/> <!-- --> </xsl:for-each> 

    You can also sort by the length of the typename attribute in reverse order. Sorting can be applied sequentially, the second will be sorted by the length attribute; thus, the group of months is also sorted:

     <xsl:for-each select="price/period"> <xsl:sort select="string-length(@typename)" order="descending"/> <xsl:sort select="@length" data-type="number"/> <!-- --> </xsl:for-each> 

    If for some reason you can only use type and length , then do so:

     <xsl:for-each select="price/period[@type!='0']"> <xsl:sort select="@type" data-type="number"/> <xsl:sort select="@length" data-type="number"/> <!-- --> </xsl:for-each> <xsl:for-each select="price/period[@type='0']"> <!-- --> </xsl:for-each> 

    The type attribute with a value of 0 processed separately, manually placing it after the rest. And all the others are sorted by type and length.

    • for the price make sorting a good idea. thank! did not guess. - gregor