XSLT 分组继续 - xPath 问题?
迪米特早些时候帮了很大的忙……这有点像第二部分。 :)
我绞尽脑汁还是没明白。
现在我能够隔离下面 xml 示例的品牌,现在我想以与隔离所有品牌大致相同的方式隔离给定 $Brand 的所有产品类型。
xml 示例(许多产品的成员之一)...
<Product>
<Brand>Brand</Brand>
<Type>Product Type (Category)</Type>
...
</Product>
这是我能够提出的 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>
再次感谢!
Dimitre was a big help earlier... this is kinda like part two. :)
I've been wracking my brain and still don't see it.
Now that I'm able to isolate the Brands of the xml example below, now I'd like to isolate all the Product-Type's of the given $Brand in much the same way as I was able to isolate all the Brands.
xml example (one member of many Products)...
<Product>
<Brand>Brand</Brand>
<Type>Product Type (Category)</Type>
...
</Product>
This is the xsl that I've been able to come up with. I think my error is in the xPath expression for the xsl:key...
<?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>
Thanks again!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
现在,您可以按
品牌
和类型
进行分组。关键必须是:现在,分组:
在模式中使用变量/参数应该是一个错误,但我认为至少 MSXSL 不会抱怨键中的这一点。 为了安全起见,请勿使用:
Now you are grouping by
Brand
andType
. The key must be:And now, the grouping:
It should be an error to use a variable/parameter in patterns, but I think that at least MSXSL does not complain about that in keys. For safety, don't use: