[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: comparison of attribute values

Subject: RE: comparison of attribute values
From: "Michael Kay" <michael.h.kay@xxxxxxxxxxxx>
Date: Fri, 31 May 2002 09:23:45 +0100
attribute value comparison xsl
> Hi,
> What I would like to do is to insert a row into a table if 
> there is a difference in an attribute value anywhere in the 
> document; for example, this data should produce 2 columns 
> (USD and EUR):

Aha, I always like it when people produce problems that justify new XSLT
2.0 / XPath 2.0 features!

<xsl:variable name="currencies" 
  select="distinct-values(//@currency)"/>

<xsl:template match="fees/*/*">
  <tr>
    <td><xsl:value-of select="name()"/></td>
    <xsl:for-each select="$currencies">
      <td>
        <xsl:value-of select="self::*[@currency=current()]/amount"/>
      </td>
    </
  </
</

In XSLT 1.0, of course, distinct-values has to be done using keys and
Muenchian grouping.

Michael Kay
Software AG
home: Michael.H.Kay@xxxxxxxxxxxx
work: Michael.Kay@xxxxxxxxxxxxxx 

> 
> <fees>
>     <basic-fees>
>         <fee1 currency="USD"><amount>20</amount></fee1>
>         <fee2 currency="EUR"><amount>25</amount></fee2>
>     </basic-fees>
>     <special-fees>
>         <fee3 currency="EUR"><amount>20</amount></fee3>
>     </special-fees>
>     <total currency="USD">65</total>
> </fees>
> 
> <!-- desired output for above doc -->
> <table>
>     <tr><td>FEE</td><td>USD</td><td>EUR</td></tr>
>     <tr><td>fee1</td><td> 20   </td><td>        </td></tr>
>     <tr><td>fee2 </td><td>        </td><td> 25  </td></tr>
>     <tr><td>fee3</td><td>        </td><td>  20  </td> </tr>
>     <tr><td>total</td><td> 65   </td><td>       </td></tr>
> </table>
> 
> but if there is only one currency used throughout the 
> document, it should only create one column (e.g., USD).
> 
> <fees>
>     <basic-fees>
>         <fee1 currency="USD"><amount>20</amount></fee1>
>         <fee2 currency="USD"><amount>25</amount></fee2>
>     </basic-fees>
>     <special-fees>
>         <fee3 currency="USD"><amount>20</amount></fee3>
>     </special-fees>
>     <total currency="USD">65</total>
> </fees>
> 
> <!-- desired output for above doc -->
> <table>
>     <tr><td> FEE </td><td>USD</td></tr>
>     <tr><td>fee1</td><td> 20   </td></tr>
>     <tr><td>fee2 </td><td> 25  </td></tr>
>     <tr><td>fee3</td><td>  20  </td> </tr>
>     <tr><td>total</td><td> 65   </td> </tr>
> </table>
> 
> 
>  I have a feeling that I'm overlooking something painfully 
> obvious, but any help would be greatly appreciated.
> 
> TIA,
> John
> 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 


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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.