Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8

Thread: position() = 1

  1. #1
    Regular Coder
    Join Date
    Jul 2002
    Posts
    128
    Thanks
    0
    Thanked 0 Times in 0 Posts

    position() = 1

    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>
    <xsltherwise>
    <div class="paraNormal">
    <xsl:value-of select="."/>
    </div>
    </xsltherwise>
    </xsl:choose>
    </xsl:template>

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

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    Newcastle, England
    Posts
    178
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #3
    Regular Coder
    Join Date
    Jul 2002
    Posts
    128
    Thanks
    0
    Thanked 0 Times in 0 Posts

    ok

    thank you very much ... but really it is impossible for me to understand why position = 1 doesn't work

  • #4
    New Coder
    Join Date
    Oct 2002
    Location
    Atlanta
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #5
    Regular Coder
    Join Date
    Jul 2002
    Posts
    128
    Thanks
    0
    Thanked 0 Times in 0 Posts

    ==

    but == doesn't exist iin xml ! ??

  • #6
    Regular Coder
    Join Date
    Jul 2002
    Posts
    128
    Thanks
    0
    Thanked 0 Times in 0 Posts

    it works

    now it works , ths first position = 2 ?? stange , but it works

  • #7
    New Coder
    Join Date
    Dec 2002
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Use count(.)=1

    Try using "count" instead...

  • #8
    Regular Coder
    Join Date
    Jul 2002
    Posts
    128
    Thanks
    0
    Thanked 0 Times in 0 Posts

    1

    thank you , now it works with 1


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •