Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Merryba 5 posts 25 karma points
    Aug 10, 2011 @ 22:32
    Merryba
    0

    correct syantax for getting position?

    How can I get the position of key('uniqueId',email)?

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Aug 10, 2011 @ 22:52
    Chriztian Steinmeier
    0

     

    Hi Merryba,

    You can count the number of preceding-siblings:

    <xsl:value-of select="count(key('uniqueId', email)/preceding-sibling::*)" />

    But the key() has to return only one item - otherwise you can't trust the value you get; It may be the position() of the last one found or it could be any other, depending on the XSLT processor...

    /Chriztian

     

  • Merryba 5 posts 25 karma points
    Aug 11, 2011 @ 16:33
    Merryba
    0

    Is there any way to check whether it is the first occurence or second occurence?

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Aug 11, 2011 @ 16:37
    Chriztian Steinmeier
    0

    Actually, can specify which one you want:

    <!-- First one: -->
    <xsl:value-of select="count(key('uniqueId', email)[1]/preceding-sibling::*)" />
    
    <!-- Last one: -->
    <xsl:value-of select="count(key('uniqueId', email)[last()]/preceding-sibling::*)" />

    /Chriztian

  • Merryba 5 posts 25 karma points
    Aug 11, 2011 @ 18:36
    Merryba
    0

    Hi Chriztian,

    Please let me know as how I can  get the count of siblings whose emailids start with the number 6 ?

  • Merryba 5 posts 25 karma points
    Aug 12, 2011 @ 21:35
    Merryba
    0
    <!-- First one: -->
    <xsl:value-ofselect="count(key('uniqueId', email)[1]/preceding-sibling::*)"/>

    <!-- Last one: -->
    <xsl:value-ofselect="count(key('uniqueId', email)[last()]/preceding-sibling::*)"/>

    This doesn't help to know whether it is first occurence or last occurence of sibling of the key element
  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Aug 16, 2011 @ 00:08
    Chriztian Steinmeier
    0

    Hi Merryba,

    Regarding the "start with the number 6" - there's a starts-with() function available for that, so you'd do something like this:

    <xsl:value-of select="count((preceding-sibling::* | following-sibling::*)[starts-with(email, '6')])" />

    About the first or last element - did you notice the predicates (square bracket stuff)? Adding [1] to an XPath selection will return only the first element - similarly, adding [last()] will return only the last element.

    /Chriztian

    PS: Could you maybe mark my first reply as the answer, so other people searching for similar problems can know there is an answer to that specific topic? Thanks. 

  • Merryba 5 posts 25 karma points
    Aug 17, 2011 @ 19:02
    Merryba
    0

    Thanks Chriztian . That helps.

Please Sign in or register to post replies

Write your reply to:

Draft