【发布时间】:2017-11-22 21:40:01
【问题描述】:
我有按顺序排列的元素。我需要根据 sec 值对元素进行分组。下面我提到了我的意见。
<body>
<title>first</title>
<entry><sec>s 2</sec><p><text>some text 1</text></p></entry>
<entry><sec>s 3</sec><p><text>some text 2</text></p></entry>
<section>section title</section>
<entry><sec>Sh 1</sec><p><text>some text 3</text></p></entry>
<entry><sec>Sh 1<sub>Pt 2</sub></sec><p><text>some text 4</text></p></entry>
<entry><sec>Sh 1<sub>item 1</sub></sec><p><text>some text 5</text></p></entry>
<entry><sec>s 8</sec><p><text>some text 2</text></p></entry>
<entry><sec>s 9</sec><p><text>some text 2</text></p></entry>
<entry><sec>Sh 2<sub>item 2</sub></sec><p><text>some text 10</text></p></entry>
<entry><sec>Sh 2</sec><p><text>some text 20</text></p></entry>
</body>
我期待下面的输出。
<body>
<title>first</title>
<entry><sec>s 2</sec><p><text>some text 1</text></p></entry>
<entry><sec>s 3</sec><p><text>some text 2</text></p></entry>
<section>section title</section>
<group>
<entry><sec>Sh 1</sec><p><text>some text 3</text></p></entry>
<entry><sec>Sh 1<sub>Pt 2</sub></sec><p><text>some text 4</text></p></entry>
<entry><sec>Sh 1<sub>item 1</sub></sec><p><text>some text 5</text></p></entry>
</group>
<entry><sec>s 8</sec><p><text>some text 2</text></p></entry>
<entry><sec>s 9</sec><p><text>some text 2</text></p></entry>
<group>
<entry><sec>Sh 2<sub>item 2</sub></sec><p><text>some text 10</text></p></entry>
<entry><sec>Sh 2</sec><p><text>some text 20</text></p></entry>
</group>
</body>
请尝试帮助我。
【问题讨论】:
-
查看任何
xsl:for-each-group group-by示例,例如在w3.org/TR/xslt20/#grouping-examples 的规范中,它应该很容易。 -
我对分组不熟悉,但我试过了。我无法带来正确的输出。请帮助某人。
-
花点时间阅读一个示例并尝试对其进行调整,如果您真的无法让它发挥作用,请向我们展示您的努力。
-
以下是我尝试的方法
跨度>