[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
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|