0

my XML tag contains many items that should be threated as three different groups, with similar (but different) sorting rules.

This is what I want to get:

<items>
    <!-- Header - for-each sorting -->
    <item name="something1_A"/>
    <item name="something2_B"/>
    <item name="something3_C"/>

    <!-- Body - for-each-group sorting -->
    <item name="something4_D"/>
    <item name="something4_E"/>
    <item name="something5_D"/>
    <item name="something5_E"/>

    <!-- Footer - for-each sorting -->
    <item name="something6_F"/>
    <item name="something6_G"/>
    <item name="something6_H"/>
</items>

Initially, items order is random.

The first sort should create those three different parts: put everything that is header on the top, everything that is footer on the bottom, and keep everything else where it is. I can determine if something should go in the header, in the body or in the footer looking at its ending (the value after the last underscore).

The second sort should work differently on each of those parts (per-element sorting for header and footer, per-group sorting for body).

I know how I can sort the header, the body and the footer (thanks to this answer), but not how to move them and sort them with different algorithms.

4

1 回答 1

2

假设你有一个template匹配的,items那么这只是将item元素分成三组的情况,你说你可以通过结尾来做到这一点:

<xsl:variable name="headerItems" select="item[
   some $suf in ('_A', '_B', '_C') satisfies ends-with(@name, $suf)]" />
<xsl:variable name="footerItems" select="item[
   some $suf in ('_F', '_G', '_H') satisfies ends-with(@name, $suf)]" />
<xsl:variable name="bodyItems"
   select="item except ($headerItems | $footerItems)" />

然后按您需要的顺序处理这三个组。

于 2013-05-30T10:00:34.463 回答