Re: [xsl] again position()?

Subject: Re: [xsl] again position()?
From: "Christopher R. Maden" <crism@xxxxxxxxx>
Date: Tue, 19 Jun 2001 03:45:59 -0700
At 03:30 19-06-2001, Daniel Bauke wrote:
at first: thanks for all earlier answers -- i'll try to use them
later.. i'm doing my xsl pages after hours, so i don't have much
time for it the more it's not so intuitive language :-)

I strongly recommend a reference like Mike Kay's _XSLT Programmer's Reference_; that will save you a lot of silly questions.


i'd like to ask for a solution for such test:
   if ((current("part") == 1) && (current("chapter") == 1))
      intro="true";
in xslt.

by current() i mean a function which returns current
position of a tag in xpath tree.

For example, current() is a well-defined XSLT function that does something entirely different, and the logical syntax is nothing like C's.


Try:

<xsl:if test="count(ancestor::part|ancestor::part/../part[1]) = 1 and
              count(ancestor::chapter|ancestor::chapter/../chapter[1]) =
                1">
  <xsl:attribute name="intro">true</xsl:attribute>
</xsl:if>

The count() expression tests if the ancestor in question is the same as the first such at that level. There may be a more efficient way, but it's too late (early?) for me right now.

HTH,
Chris
your solution for espresso-pizza-and-Zappa-fueled 24-hour XSLT support
--
Christopher R. Maden, XML Consultant
DTDs/schemas - conversion - ebooks - publishing - Web - B2B - training
<URL: http://crism.maden.org/consulting/ >
PGP Fingerprint: BBA6 4085 DED0 E176 D6D4  5DFC AC52 F825 AFEC 58DA


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



Current Thread