有xml。我从中形成一个 Html 页面。
<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>
如何组织一个周期的排序,以便第一个节点进入1 个月、2 个月......1 年 ..,永久许可?
<xsl:for-each select="price/period">
<xsl:sort select="???"/>
<!--мои действия с нодом -->
</xsl:for-each>
您需要以某种方式组织排序功能,条件类似于
助记符
if type = 1 then return length * 30
if type = 3 then return length * 365
if type = 0 then return 1000000
在我看来,最简单的方法是按价格排序:
您还可以按
typename
相反的顺序按属性长度排序。排序可以按顺序应用,第二个将按属性排序length
;所以月份组也被排序:如果由于某种原因你只能使用
type
andlength
,那么这样做:type
我们单独处理具有值的属性0
,手动将其放在其他属性之后。所有其他的都按类型和长度排序。