我在为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 我认为它可能是当前分组密钥的功能,但我不能应用它。你知道吗?
发布于 2015-10-01 18:51:19
试试这个:
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 Whohttps://stackoverflow.com/questions/32876907
复制相似问题