我在为HTML表创建XSLT模板时遇到问题。我有以下XML数据,我需要创建一个摘要。
<doc-number>1</doc-number>
<book>Gardening/John Smith</book>
<call-no>B-1</call-no>
<doc-number>1</doc-number>
<book>Gardening/John Smith</book>
<call-no>B-1/23</call-no>
<doc-number>1</doc-number>
<book>Forest/Ema Who</book>
<call-no>A-1/2</call-no>
<doc-number>1</doc-number>
<book>Gardening/John Smith</book>
<call-no>B-1/5</call-no>
我需要这个:
Items Book
3 Gardening/John Smith
1 Forest/Ema Who
我认为它可能与current-grouping-key有关,但我不能应用它。你知道吗?
答案 0 :(得分:0)
试试这个:
<强> XML:强>
<root>
<doc-number>1</doc-number>
<book>Gardening/John Smith</book>
<call-no>B-1</call-no>
<doc-number>1</doc-number>
<book>Gardening/John Smith</book>
<call-no>B-1/23</call-no>
<doc-number>1</doc-number>
<book>Forest/Ema Who</book>
<call-no>A-1/2</call-no>
<doc-number>1</doc-number>
<book>Gardening/John Smith</book>
<call-no>B-1/5</call-no>
</root>
<强> XSLT:强>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output omit-xml-declaration="yes"/>
<xsl:template match="root">
<xsl:text>Items   Books </xsl:text>
<xsl:for-each-group select="book" group-by=".">
<xsl:value-of select="count(current-group())"/>   <xsl:value-of select="current-grouping-key()"/>
<xsl:text> </xsl:text>
</xsl:for-each-group>
</xsl:template>
</xsl:stylesheet>
<强>输出:强>
Items Books
3 Gardening/John Smith
1 Forest/Ema Who