PDA

View Full Version : position() = 1


jeorg
11-30-2002, 11:06 AM
this code doesn't work

if I do position()!=last i tworks , but I want to apply a different style on the first element

------------------------------------------------------------

<xsl:template match="/conditions/condition/para">
<xsl:choose>
<xsl:when test="position()=1">
<div class="paraDebut">
<xsl:value-of select="."/>
</div>
</xsl:when>
<xsl:otherwise>
<div class="paraNormal">
<xsl:value-of select="."/>
</div>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

--------------------------------------------------------
thank you

mpjbrennan
12-03-2002, 10:41 AM
To get at the first item use the xsl:sort command to process the nodes inthe reverse order. Here's an example:


XML file
<?xml version="1.0"?>
<root>
<item>This is the first item</item>
<item>This is item 2</item>
<item>This is item 3</item>
<item>This is item 4</item>
<item>This is the last item</item>
</root>

XSL file
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="/">
<html>
<body>
<xsl:for-each select="root/item">
<xsl:sort select="position()" data-type="number" order="descending" />
<xsl:if test="position()=last()">
<p>
<xsl:value-of select="." /><br />
</p>
</xsl:if>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

happy coding!

patrick

jeorg
12-03-2002, 10:46 AM
thank you very much ... but really it is impossible for me to understand why position = 1 doesn't work

dhtroy
12-03-2002, 05:46 PM
haven't tried this - just a "might wanna try this"

Try

1 = position()

position() == 1

1 == position()

wasn't certain about the '=' verse '==' ya never know.

jeorg
12-03-2002, 07:07 PM
but == doesn't exist iin xml ! ??

jeorg
12-04-2002, 02:00 PM
now it works , ths first position = 2 ?? stange , but it works

Joseph McGarvey
12-04-2002, 08:39 PM
Try using "count" instead...

jeorg
12-05-2002, 10:59 AM
thank you , now it works with 1