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

Re: How to get a "heading" from an element

Subject: Re: How to get a "heading" from an element
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Sun, 10 Feb 2002 17:24:16 +0000
xsl if two conditions
Hi Roger,

>>You can compare its airline-name with this airline's airline-name
>>with:
>>
>>  preceding-sibling::airline[1]/airline-name != airline-name
[snip]
> Thanks for this! I had just one problem, ie the very first
> airline-name didn't come out, so I changed the above to:
>
> <xsl:variable name="var-num"><xsl:number/></xsl:variable>
> <xsl:if test="$var-num = 1">
>     <tr>
>       <td><xsl:value-of select="airline-name" /></td>
>     </tr>
> </xsl:if>
>  <xsl:if test="preceding-sibling::airline[1]/airline-name !=
airline-name">>
>     <tr>
>       <td><xsl:value-of select="airline-name" /></td>
>     </tr>
>   </xsl:if>
>   <tr>
>     <td><xsl:value-of select="airport-code" /></td>
>     <td><xsl:value-of select="airport-name" /></td>
>   </tr>
>
> It works, but is there a better way?

Whoops, sorry about that! You can do what you have done, of course,
but using xsl:number is pretty inefficient, and it's a bit of a waste
having two separate xsl:ifs that generate exactly the same result when
you could combine the two conditions with an 'or'.

I recommend you either do:

  <xsl:if test="position() = 1 or
                preceding-sibling::airline[1]/airline-name !=
                airline-name">
    ...
  </xsl:if>

Or, possibly better:

  <xsl:if test="not(preceding-sibling::airline[1]/airline-name =
                    airline-name)">
    ...
  </xsl:if>

This highlights the difference between A != B and not(A = B). The A !=
B checks whether there *is* a preceding sibling airline element whose
airline-name *isn't* the same as this one's airline-name. The not(A =
B) checks whether there *isn't* a preceding sibling airline element
whose airline-name *is* the same as this one's airline-name. So the
latter includes the first airline element (since it doesn't have a
preceding sibling airline at all, let alone one whose airline-name is
the same as this one's). Whereas the former doesn't include the first
airline element.

Sorry about my mistake,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 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.