我對使用組有所不同,希望能夠使用position()選擇組的子集。XSLT2選擇一個組的子集
我已經有這個代碼的工作,因爲我想(根據需要創建組和正確的輸出)。
<xsl:template match="Locations">
<table>
<tbody>
<xsl:for-each-group select="Location" group-by="Country">
<xsl:sort data-type="text" order="ascending" select="."/>
<xsl:for-each-group select="current-group()" group-by="current-grouping-key()">
</xsl:for-each-group>
<tr>
<td class="country"><xsl:value-of select="current-grouping-key()"/></td>
</tr>
<xsl:for-each-group select="current-group()" group-by="City">
<xsl:sort data-type="text" order="ascending" select="current-grouping-key()"/>
<tr>
<td class="city"><xsl:value-of select="fn:current-grouping-key()"/></td>
</tr>
</xsl:for-each-group>
</xsl:for-each-group>
</tbody>
</table>
</xsl:template>
如果我想只是打通第二第四國家標籤,我會怎麼做呢?我嘗試了position(),但不是獲取一個數字,而是得到了分組鍵值,例如CA.
這是源XML:
<Locations> <Location> <Country>US</Country> <City>New York</City> </Location> <Location> <Country>US</Country> <City>Houston</City> </Location> <Location> <Country>MX</Country> <City>Cancun</City> </Location> <Location> <Country>CH</Country> <City>Zurich</City> </Location> <Location> <Country>CA</Country> <City>Toronto</City> </Location> <Location> <Country>DE</Country> <City>Berlin</City> </Location> <Location> <Country>JP</Country> <City>Tokyo</City> </Location> <Location> <Country>GB</Country> <City>London</City> </Location> <Location> <Country>CA</Country> <City>Edmonton</City> </Location> </Locations>
任何幫助將不勝感激。提前致謝。
你能告訴你在這種情況下,期待輸出?如果你嘗試使用'position()',它可能也會有所幫助。謝謝! –