创建页面索引 -Xslt 1.0 -

Create page index -Xslt 1.0 -

这是我的 XML:

<SECTION_CONTENT_LIST>
    <SECTION_CONTENT_LIST_ITEM>
        <NTC_LIGHTLISTPRODUCT>
            <REGION>10-Mediterraneo Occidentale - Francia</REGION>
            <ITA_LIGHT_NUMBER>0840</ITA_LIGHT_NUMBER>
        </NTC_LIGHTLISTPRODUCT>
    </SECTION_CONTENT_LIST_ITEM>
    <SECTION_CONTENT_LIST_ITEM>
        <NTC_LIGHTLISTPRODUCT>
            <REGION>10-Mediterraneo Occidentale - Francia</REGION>
            <ITA_LIGHT_NUMBER>0843</ITA_LIGHT_NUMBER>
        </NTC_LIGHTLISTPRODUCT>
    </SECTION_CONTENT_LIST_ITEM>        
    <SECTION_CONTENT_LIST_ITEM>
        <NTC_LIGHTLISTPRODUCT>
            <REGION>10-Mediterraneo Occidentale - Francia</REGION>
            <ITA_LIGHT_NUMBER>0850</ITA_LIGHT_NUMBER>
        </NTC_LIGHTLISTPRODUCT>
    </SECTION_CONTENT_LIST_ITEM>        
    <SECTION_CONTENT_LIST_ITEM>
        <NTC_LIGHTLISTPRODUCT>
            <REGION>16-Mar Tirreno - Francia (Corsica)</REGION>
            <ITA_LIGHT_NUMBER>0906</ITA_LIGHT_NUMBER>
        </NTC_LIGHTLISTPRODUCT>
    </SECTION_CONTENT_LIST_ITEM>
    <SECTION_CONTENT_LIST_ITEM>
        <NTC_LIGHTLISTPRODUCT>
            <REGION>16-Mar Tirreno - Francia (Corsica)</REGION>
            <ITA_LIGHT_NUMBER>0922.15</ITA_LIGHT_NUMBER>
        </NTC_LIGHTLISTPRODUCT>
    </SECTION_CONTENT_LIST_ITEM>
    <SECTION_CONTENT_LIST_ITEM>
        <NTC_LIGHTLISTPRODUCT>
            <REGION>25-Mare Adriatico - Slovenia</REGION>
            <ITA_LIGHT_NUMBER>3620</ITA_LIGHT_NUMBER>
        </NTC_LIGHTLISTPRODUCT>
    </SECTION_CONTENT_LIST_ITEM>
</SECTION_CONTENT_LIST>

这是我的 XSLT 1.0:

<table style='border-collapse:collapse;  width:100%; align:center' cellspacing="0" cellpadding="0">
    <xsl:for-each select="//ITA_LIGHT_NUMBER">
    <xsl:sort select="." order="ascending" data-type="text"/>                                           
        <tr style="line-height:0.78cm">
            <xsl:variable name="regione" select="preceding-sibling::REGION"/>
            <td style="height:0.68cm;border-bottom:dotted 1.0">
                <xsl:if test="following::REGION != $regione">
                    <xsl:value-of select="preceding-sibling::REGION"/>
                </xsl:if>
            </td>

            <td style="height:0.68cm;border-bottom:dotted 1.0">
                    <xsl:value-of select="."/>
            </td>
        </tr>   
    </xsl:for-each>
</table>

这会在两列中创建一个 table。在第一列写 Region,在第二列写 ITA_LIGHT_NUMBER.

10-Mediterraneo Occidentale - 法国 0840
10-Mediterraneo Occidentale - 法国 0843
10-Mediterraneo Occidentale - 法国 0850
3 月 16 日蒂雷诺 - 法兰西亚(科西嘉岛)0906
3 月 16 日蒂雷诺 - 法兰西亚(科西嘉岛)0922.15
25-Mare Adriatico - 斯洛文尼亚 3620

但我想要这个输出:

10-Mediterraneo Occidentale - 法国 0840 - 0850
3 月 16 日 Tirreno - Francia (Corsica) 0906 - 0922.15
25-Mare Adriatico - 斯洛文尼亚 3620

实际上:写入第一个区域和第一个ITA_LIGHT_NAME,如果后面的区域与当前区域不同,则写入ITA_LIGHT_NUMBER。

如果你使用按键就更好了。

例如在 XSLT 的开头定义它:

<xsl:key name="lightproducts" match="NTC_LIGHTLISTPRODUCT" use="REGION"/>

您可以按如下方式修改您的模板:

  <table style='border-collapse:collapse;  width:100%; align:center' cellspacing="0" cellpadding="0">
      <xsl:for-each select="//NTC_LIGHTLISTPRODUCT">
          <xsl:sort select="REGION" order="ascending" data-type="text"/>
          <xsl:variable name="regione" select="REGION" />

          <xsl:if test="not(preceding::NTC_LIGHTLISTPRODUCT[REGION/text() = $regione])">
              <tr style="line-height:0.78cm">
                  <td style="height:0.68cm;border-bottom:dotted 1.0">
                      <xsl:value-of select="$regione"/>
                  </td>
                  <td style="height:0.68cm;border-bottom:dotted 1.0">
                      <xsl:for-each select="key('lightproducts', $regione)">
                          <xsl:sort select="ITA_LIGHT_NUMBER"/>
                          <xsl:choose>
                              <xsl:when test="last() = 1">
                                  <xsl:value-of select="ITA_LIGHT_NUMBER"/>
                              </xsl:when>
                              <xsl:when test="position() = 1">
                                  <xsl:value-of select="ITA_LIGHT_NUMBER"/>
                              </xsl:when>
                              <xsl:when test="position() = last()">
                                  <xsl:text>-</xsl:text>
                                  <xsl:value-of select="ITA_LIGHT_NUMBER"/>
                              </xsl:when>
                          </xsl:choose>
                      </xsl:for-each>
                  </td>
              </tr>
          </xsl:if>
      </xsl:for-each>
  </table>

这是我从你的输入中得到的

<?xml version="1.0" encoding="utf-8"?>
<table style="border-collapse:collapse;  width:100%; align:center" cellspacing="0" cellpadding="0">
   <tr style="line-height:0.78cm">
      <td style="height:0.68cm;border-bottom:dotted 1.0">10-Mediterraneo Occidentale - Francia</td>
      <td style="height:0.68cm;border-bottom:dotted 1.0">0840-0850</td>
   </tr>
   <tr style="line-height:0.78cm">
      <td style="height:0.68cm;border-bottom:dotted 1.0">16-Mar Tirreno - Francia (Corsica)</td>
      <td style="height:0.68cm;border-bottom:dotted 1.0">0906-0922.15</td>
   </tr>
   <tr style="line-height:0.78cm">
      <td style="height:0.68cm;border-bottom:dotted 1.0">25-Mare Adriatico - Slovenia</td>
      <td style="height:0.68cm;border-bottom:dotted 1.0">3620</td>
   </tr>
</table>