| Subject: Re: [xsl] Finding nester distinct items From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Mon, 10 Mar 2003 14:55:17 -0500 | 
What I need is to get a distinct list of Pole val's and then for each Pole a distinct list of Time val's. (I need to be able to recreate this http://www.intermatic.com/comind/fdff.htm).
T:\ftemp>type craig.xml <products> <product id="439" model="FD12H"> <desc>text</desc> <product_fact id="5" name="Finish"> <val>Ivory Decorative</val> </product_fact> <product_fact id="8" name="Hold"> <val>no</val> </product_fact> <product_fact id="6" name="Pole"> <val>SPST</val> </product_fact> <product_fact id="7" name="Time"> <val>12 hours</val> </product_fact> </product> <product id="439" model="FD6H"> <desc>text</desc> <product_fact id="5" name="Finish"> <val>Ivory Decorative</val> </product_fact> <product_fact id="8" name="Hold"> <val>no</val> </product_fact> <product_fact id="6" name="Pole"> <val>SPST</val> </product_fact> <product_fact id="7" name="Time"> <val>6 hours</val> </product_fact> </product> <product id="439" model="FD6HH"> <desc>text</desc> <product_fact id="5" name="Finish"> <val>Ivory Decorative</val> </product_fact> <product_fact id="8" name="Hold"> <val>no</val> </product_fact> <product_fact id="6" name="Pole"> <val>SPST</val> </product_fact> <product_fact id="7" name="Time"> <val>6 hours</val> </product_fact> </product> <product id="439" model="FD4H"> <desc>text</desc> <product_fact id="5" name="Finish"> <val>Ivory Decorative</val> </product_fact> <product_fact id="8" name="Hold"> <val>no</val> </product_fact> <product_fact id="6" name="Pole"> <val>SPDT</val> </product_fact> <product_fact id="7" name="Time"> <val>4 hours</val> </product_fact> </product> </products>
T:\ftemp>type craig.xsl <?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
  <xsl:variable name="products" select="/products/product"/>
  <xsl:for-each select="$products">
    <xsl:if test="generate-id(.) =
                  generate-id( $products[ product_fact[@name='Pole']/val=
                                current()/product_fact[@name='Pole']/val ])">
      <xsl:value-of select="product_fact[@name='Pole']/val"/>
      <xsl:text>
</xsl:text>
      <xsl:variable name="times"
                    select="$products[ product_fact[@name='Pole']/val=
                             current()/product_fact[@name='Pole']/val ]"/>
      <xsl:for-each select="$times">
        <xsl:if test="generate-id(.) =
                      generate-id( $times[ product_fact[@name='Time']/val=
                                 current()/product_fact[@name='Time']/val ])">
          <xsl:text>      </xsl:text>
          <xsl:value-of select="product_fact[@name='Time']/val"/>
          <xsl:text>
</xsl:text>
          <xsl:for-each select="$times[ product_fact[@name='Time']/val=
                              current()/product_fact[@name='Time']/val ]">            <xsl:text>             </xsl:text>
            <xsl:value-of select="@model"/>
            <xsl:text>
</xsl:text>
          </xsl:for-each>
        </xsl:if>
      </xsl:for-each>
    </xsl:if>
  </xsl:for-each>
</xsl:template>T:\ftemp>saxon craig.xml craig.xsl
SPST
      12 hours
             FD12H
      6 hours
             FD6H
             FD6HH
SPDT
      4 hours
             FD4H
-- Upcoming hands-on in-depth XSLT/XPath and/or XSL-FO North America: June 16-20, 2003
G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (F:-0995) ISBN 0-13-065196-6 Definitive XSLT and XPath ISBN 0-13-140374-5 Definitive XSL-FO ISBN 1-894049-08-X Practical Transformation Using XSLT and XPath ISBN 1-894049-10-1 Practical Formatting Using XSL-FO Male Breast Cancer Awareness http://www.CraneSoftwrights.com/s/bc
| Current Thread | 
|---|
| 
 | 
| <- Previous | Index | Next -> | 
|---|---|---|
| [xsl] Finding nester distinct items, Craig Kattner | Thread | [xsl] Conversions for PeopleSoft in, Shoe, Bridget | 
| [xsl] how to select elements based , Robert P. J. Day | Date | RE: [xsl] Get Position of Node in A, Michael Kay | 
| Month |