This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: formatting first item differently than the rest
- To: Eric Taylor <Eric dot Taylor at RealPage dot com>
- Subject: Re: formatting first item differently than the rest
- From: Jeni Tennison <jeni at friday dot u-net dot com>
- Date: Tue, 08 Aug 2000 19:53:26 +0100
- Cc: XSL-List at mulberrytech dot com
- Reply-To: xsl-list at mulberrytech dot com
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@epistemics.co.uk
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list