views:

25

answers:

1

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"&gt;
  <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!

+1  A: 

Now you are grouping by Brand and Type. The key must be:

<xsl:key name="kProdByBrandAndType" 
         match="Product" use="concat(Brand,'+++',Type)"/> 

And now, the grouping:

<xsl:for-each  
          select="Product[generate-id() =  
                          generate-id(key('kProdByBrandAndType',
                                          concat($Brand,'+++',Type))[1])]">

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:

<xsl:key name="kProdByType" match="Product[Brand=$Brand]" use="Type"/> 
Alejandro
BAMM!!! THANKS!!!
Jimmmy
@Jimmmy: You are wellcome!
Alejandro