从昨天开始跟进我的xslt问题,链接在下面找到。
first last element 2nd variation
我必须将每个部分的第一页和最后一页编号输出到表格中。
我很困惑从哪里开始。非常感谢XSLT 1.0解决方案和XSLT 2.0解决方案。我真的很感激任何给定的帮助。
关心JJ。
INPUT:
<root>
<page number="1" section="Arsenal">Arsenal</page>
<page number="2" section="Arsenal">Arsenal</page>
<page number="3" section="Arsenal">Arsenal</page>
<page number="4" section="Arsenal">Arsenal</page>
<page number="5" section="Arsenal">Arsenal</page>
<page number="6" section="Arsenal">Arsenal</page>
<page number="7" section="Chelsea">Chelsea</page>
<page number="8" section="Chelsea">Chelsea</page>
<page number="9" section="Chelsea">Chelsea</page>
<page number="10" section="Chelsea">Chelsea</page>
<page number="11" section="Chelsea">Chelsea</page>
<page number="12" section="Chelsea">Chelsea</page>
<page number="13" section="ManUnited">ManUnited</page>
<page number="14" section="ManUnited">ManUnited</page>
<page number="15" section="ManUnited">ManUnited</page>
<page number="16" section="ManUnited">ManUnited</page>
<page number="17" section="ManUnited">ManUnited</page>
<page number="18" section="ManUnited">ManUnited</page>
<page number="19" section="ManCity">ManCity</page>
<page number="20" section="ManCity">ManCity</page>
<page number="21" section="ManCity">ManCity</page>
<page number="22" section="ManCity">ManCity</page>
<page number="23" section="ManCity">ManCity</page>
<page number="24" section="ManCity">ManCity</page>
</root>
输出:
<tr><td>1</td><td>Arsenal</td><td>6</td></tr>
<tr><td>7</td><td>Chelsea</td><td>12</td></tr>
<tr><td>13</td><td>ManU</td><td>18</td></tr>
<tr><td>19</td><td>Mancity</td><td>24</td></tr>
答案 0 :(得分:1)
使用:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
<xsl:key name="k" match="page" use="@section"/>
<xsl:template match="/root">
<table>
<xsl:apply-templates select="page[generate-id() = generate-id(key('k', @section))]"/>
</table>
</xsl:template>
<xsl:template match="page">
<tr>
<td>
<xsl:value-of select="@number"/>
</td>
<td>
<xsl:value-of select="."/>
</td>
<td>
<xsl:value-of select="key('k', @section)[last()]/@number"/>
</td>
</tr>
</xsl:template>
</xsl:stylesheet>
输出:
<table>
<tr>
<td>1</td>
<td>Arsenal</td>
<td>6</td>
</tr>
<tr>
<td>7</td>
<td>Chelsea</td>
<td>12</td>
</tr>
<tr>
<td>13</td>
<td>ManUnited</td>
<td>18</td>
</tr>
<tr>
<td>19</td>
<td>ManCity</td>
<td>24</td>
</tr>
</table>