0

Dimitre は前に大きな助けになりました... これはパート 2 のようなものです。:)

私は頭を悩ませてきましたが、まだ見えません。

以下の xml の例のブランドを分離できるようになったので、すべてのブランドを分離できたのとほぼ同じ方法で、指定された $Brand のすべての製品タイプを分離したいと考えています。

xml の例 (多くの製品の 1 つのメンバー)...

<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 に答える