0

Dimitre 早些时候帮了大忙……这有点像第二部分。:)

我一直在绞尽脑汁,仍然没有看到它。

现在我能够隔离下面 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>

再次感谢!

4

1 回答 1

1

现在您按Brand和分组Type。关键必须是:

<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"/> 
于 2010-08-17T21:25:21.893 回答