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

Re: formatting first item differently than the rest

Subject: Re: formatting first item differently than the rest
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Tue, 08 Aug 2000 19:53:26 +0100
xsl if first item
Eric,

>I want to format the section title one way if this is the first <fieldlist>,
>and slightly differently for number 2ff.  I'm not sure what the syntax is to
>do this.

Conditional processing usually involves either xsl:if or
xsl:choose/xsl:when/xsl:otherwise.  When you want to do something if
something is the case, and not if it isn't, then it's best to use xsl:if:

<xsl:if test="...">
  <!-- if the test is true -->
</xsl:if>
<!-- whatever the case -->

When you want to do one thing if something and something different if
something else, then it's best to use xsl:choose/xsl:when/xsl:otherwise:

<xsl:choose>
  <xsl:when test="...">
    <!-- if the test is true -->
  </xsl:when>
  <!-- more xsl:whens -->
  <xsl:otherwise>
    <!-- if none of the xsl:whens have been true -->
  </xsl:otherwise>
</xsl:choose>

In your case, you want to check whether the 'fieldlist' you're currently
looking at is the first one.  As you are iterating over all the fieldlists,
you can use position() for this.  position() gives you the position of the
current node in the current node list.  Within the xsl:for-each, the
current node is the fieldlist you're looking at, and the current node list
is the list of all the fieldlists that are children of the particular
fields element.

So, you can do:

<xsl:choose>
  <xsl:when test="position() = 1">
    <!-- processing of the first fieldlist -->
  </xsl:when>
  <xsl:otherwise>
    <!-- processing of the other fieldlists -->
  </xsl:otherwise>
</xsl:choose>

And depending on how different the processing is, you might find xsl:if
appropriate as well:

<xsl:if test="position() = 1">
  <!-- processing of the first fieldlist -->
</xsl:if>
<!-- processing of *all* the fieldlists -->

I hope this helps,

Jeni

Dr Jeni Tennison
Epistemics Ltd * Strelley Hall * Nottingham * NG8 6PE
tel: 0115 906 1301 * fax: 0115 906 1304 * email: jeni.tennison@xxxxxxxxxxxxxxxx


 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.