[xsl] Using Foreach with Attribute values

Subject: [xsl] Using Foreach with Attribute values
From: "Manuel Reyes" <Manuel.Reyes@xxxxxxxxx>
Date: Wed, 10 Dec 2003 11:57:32 -0000
I am attempting to merge an XSL and XML file to generate a PDF, and I
have encountered a problem that I can't find a solution to.

The XML file that I am working with has the following format:

    <product category="Cat 1">
    <product category="Cat 2">
    <product category="Cat 3">
    <product category="Cat 2">

As you can see there are 2 products of type "Cat 2", now what I am
attempting to achieve is to create a PDF (using Apache FOP) with 3
tables (one for each category) and within each table put the values that
have that category.  So something like this:

Cat 1
valA valB

Cat 2
valC valD
valG valH

Cat 3
valE valF

I have managed to do simple foreach, but I can't seem to find a way of
doing this using the "category" attribute to group items.

One thing that could be an issue here, is that I don't have any control
of the "category" attribute value, so it isn't possible to hardcode the
XSL file to pull out specific values by attribute value.  In other words
this needs to be 100% dynamic, as on 1 run the XML may have 2 categories
and 6 products, on another it may have 40 categories and 500 products.

Manuel Reyes


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Current Thread