Xml XSLT分组继续-xPath问题?
迪米特里之前帮了大忙。。。这有点像第二部分 我一直在绞尽脑汁,但还是看不见 现在我已经能够隔离下面xml示例中的品牌,现在我想隔离给定$Brand的所有产品类型,方法与隔离所有品牌的方法大致相同 xml示例(许多产品中的一个成员)Xml XSLT分组继续-xPath问题?,xml,xslt,xpath,xslt-grouping,Xml,Xslt,Xpath,Xslt Grouping,迪米特里之前帮了大忙。。。这有点像第二部分 我一直在绞尽脑汁,但还是看不见 现在我已经能够隔离下面xml示例中的品牌,现在我想隔离给定$Brand的所有产品类型,方法与隔离所有品牌的方法大致相同 xml示例(许多产品中的一个成员) 烙印 产品类型(类别) ... 这就是我能够想到的xsl。我想我的错误在xsl:key的xPath表达式中 <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0"
烙印
产品类型(类别)
...
这就是我能够想到的xsl。我想我的错误在xsl:key的xPath表达式中
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="Brand" select="Brand"/>
<xsl:output method="html" encoding="utf-8"/>
<xsl:key name="kProdByType"
match="Products/Product/Brand[. = $Brand]" use="../Type"/>
<xsl:template match="Products">
<xsl:for-each
select="Product[generate-id() =
generate-id(key('kProdByType', Type)[1])]
"><xsl:sort select="Type" /><xsl:value-of
select="Type" />|</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
|
再次感谢 现在您正在按
品牌
和类型
进行分组。关键必须是:
<xsl:key name="kProdByBrandAndType"
match="Product" use="concat(Brand,'+++',Type)"/>
现在,分组:
<xsl:for-each
select="Product[generate-id() =
generate-id(key('kProdByBrandAndType',
concat($Brand,'+++',Type))[1])]">
在模式中使用变量/参数应该是错误的,但我认为至少MSXSL不会在键中抱怨这一点为安全起见,请勿使用:
<xsl:key name="kProdByType" match="Product[Brand=$Brand]" use="Type"/>
<xsl:key name="kProdByType" match="Product[Brand=$Brand]" use="Type"/>