Subject: Re: formatting first item differently than the rest From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx> Date: Tue, 08 Aug 2000 19:53:26 +0100 |
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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
formatting first item differently t, Eric Taylor | Thread | RE: formatting first item different, Spychalski, Frank |
Re: XMTP XML file breaks Saxon and , Steve Muench | Date | Re: Testing for CDATA, Jeni Tennison |
Month |