Search

I am writing some xslt to display a league table, now what I want to do is display the number of the record, so for the top record I want it to display 1 obviously, and all the way down to 50.

How do I display that?

do you have a sample xml you can post?

sure

<county-men-averages>
    <section id="2" handle="county-men-averages">County Men Averages</section>
    <entry id="2">
        <player handle="derek-williams">Derek Williams</player>
        <team handle="penyffordd-rbl">Penyffordd RBL</team>
        <played handle="1">1</played>
        <won handle="1">1</won>
        <lost handle="0">0</lost>
        <average handle="3340">33.40</average>
        <dart-average handle="3440">34.40</dart-average>
    </entry>
    <entry id="3">
        <player handle="paul-dulson">Paul Dulson</player>
        <team handle="st-marys-cc">St Mary's CC</team>
        <played handle="2">2</played>
        <won handle="2">2</won>
        <lost handle="0">0</lost>
        <average handle="2697">26.97</average>
        <dart-average handle="2897">28.97</dart-average>
    </entry>
    <entry id="4">
        <player handle="mark-pritchard">Mark Pritchard</player>
        <team handle="stanton-house">Stanton House</team>
        <played handle="1">1</played>
        <won handle="1">1</won>
        <lost handle="0">0</lost>
        <average handle="2637">26.37</average>
        <dart-average handle="2737">27.37</dart-average>
    </entry>
</county-men-averages>

Try this (in your entry template):

<xsl:value-of select="position()"/>

Brilliant.

Thanks guys.

couple different ways you can write this - apply-templates or for-each. I prefer the former for neatness.

anyway, here’s a quick one if you’re just getting the entry/@id value:

<xsl:apply-templates match="data">
<table> <!-- add all required table attributes -->
    <thead>
        <tr>
            <xsl:apply-templates select="county-men-averages/entry" mode="head" />
        </tr>
    </thead>
</table>
</xsl:apply-templates>
<xsl:apply-templates match="county-men-averages/entry" mode="head">
    <td><xsl:value-of select="@id" /></td>
</xsl:apply-templates>

is that something along the lines you’re looking for?

@michael-e, if you’re traversing through the tree and do position() on an entry, won’t that always return 1? i guess it depends on how you’re looping through it

The position() works for me. This is the resulting page:

http://test.nicktoye.co.uk/ccd/county/mens-averages

@wdtan: No, it would work in the XSL you posted. Each entry “knows” its position.

@NickToye: Your test page looks great! Please consider clickable links using Markdown. In this case you can simply use the shortcut style, typing:

<http://test.nicktoye.co.uk/ccd/county/mens-averages>

This will result in:

http://test.nicktoye.co.uk/ccd/county/mens-averages

aight, cool. looks good. i just got into playing darts - mighty fun! @nick, are you in this league as well or just making the site?

@michael-e - thanks. always forget how position() always works without testing it out…and always seem to do things in a very verbose way!

XSLT is so damned cool, isn’t it?

making the site. My wife and sister play in the league. It’s a freebie I promised ages ago, and have only just got around to it.

One thing I’d add is that for numbers (eg the averages field in your section), if you are ever going to want to sort these in the Data Source then be sure to use a Number field and not a Text input field. Then you’ll get native sorting if you need it.

I am already sorting in the DS, via the D/Ave. What benefits would the native sorting give me. Just out of interest?

If you’re using a Text field then values will be sorted alphabetically. So if you had the following:

1 2 3 10 20 30

Sorting using a Text field would give you:

1 10 2 20 3 30

Whereas if this was a Number field you would get true numeric ordering.

Maybe I’m wrong though.

If it’s native, it’s going to be more efficient.

This looks like it’s working though, I am sorting the D/Ave

If it’s more efficient I may need to change it.

but now it removes the trailing zero’s from after the decimal point.

http://www.w3schools.com/XSL/func_formatnumber.asp

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details