XSL : Knowing the position of a node in a collection XML

Laurent Bientz

Imagine an XML stream composed of a collection of the same family (eg staff) and you want to know XSL in the position of a node in this position from a predicate where ([] in XPath).

Let the flow of XML of previous post slightly modified:

<?xml version="1.0" encoding="UTF-8"?>
                <name>Laurent Bientz</name>
                <name>Florian Collot</name>
                <name>Kevin Lancien</name>
                <name>Nicolas Nowak</name>
                <name>Jacques De Lamballerie</name>
                <name>Katty Dida</name>
            <staff xp="iOs">
                <name>Loic Couharde</name>
                <name>Julien Quievreux</name>
                <name>Jean-Baptiste Chateaux</name>
            <!-- ... -->

Here, we want to know the position of Loic Couharde in wandiz/staff collection from its xp "iOS"

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:php="http://php.net/xsl" xmlns="http://www.w3.org/1999/xhtml">
    <xsl:template name="whereIsSteveJobs">
        <xsl:variable name="iOsPosition" select="count(//View/wandiz/staff[@xp = 'iOs']/preceding-sibling::*)+1" />
        Position n°<xsl:value-of select="$iOsPosition" /> in /wandiz/staff


Prodan - 2013-09-02 03:51:42
Your example worked like a charm. Works great for an upcoming project/requirement I have. What I need now is an example of how to limit the number of feeds. I am not a programmer, so very explicit examples apprecited. Thanks for your work.
Outlet - 2013-09-04 09:18:43
Pretty! This was a really wonderful article. Thank you for supplying this information.
toms - 2013-09-12 05:04:26
Hello there! I know this is kind of off topic but I was wondering if you knew where I could find a captcha plugin for my comment form? I'm using the same blog platform as yours and I'm having difficulty finding one? Thanks a lot!
XRumerTest - 2017-05-13 13:29:07
Hello. And Bye.



Wandi invites you to discover a new approach to navigating a website...
Are you ready?

Launch the experience