counting...

T

The alMIGHTY N

Hi, I'm trying to create essentially an ordered list of items.

<games>
<game>
<title>Legend of Zelda: Twilight Princess</title>
<system>Nintendo Wii</system>
</game>
<game>
<title>Metal Gear Solid 4</title>
<system>Sony Playstation 3</system>
</game>
<game>
<title>Elite Beat Agents</title>
<system>Nintendo DS</system>
</game>
<game>
<title>Gears of War</title>
<system>Microsoft Xbox 360</system>
</game>
<game>
<title>Grand Theft Auto: Vice City Stories</title>
<system>Sony PSP</system>
</game>
</games>

I want to produce:

<ul>
<li>1 - Legend of Zelda: Twilight Princess</li>
<li>2 - Metal Gear Solid 4</li>
<li>3 - Elite Beat Agents</li>
<li>4 - Gears of War</li>
<li>5 - Grand Theft Auto: Vice City Stories</li>
</ul>

I know I can just use <ol> instead of <ul> but I'm trying to learn how
to do it functionally through XSL instead.

Thanks,

Nathaniel
 
M

Martin Honnen

The said:
Hi, I'm trying to create essentially an ordered list of items.
I know I can just use <ol> instead of <ul> but I'm trying to learn how
to do it functionally through XSL instead.

There are several ways, one is the position function e.g.
<xsl:template match="games">
<html>
<body>
<ul>
<xsl:apply-templates select="game"/>
</ul>
</body>
</html>
</xsl:template>

<xsl:template match="game">
<li>
<xsl:value-of select="concat(position(), ' - ')"/>
<xsl:apply-templates select="title"/>
</li>
</xsl:template>

<xsl:template match="title">
<xsl:value-of select="."/>
</xsl:template>

Or look into xsl:number <http://www.w3.org/TR/xslt#number>.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,007
Messages
2,570,266
Members
46,865
Latest member
AveryHamme

Latest Threads

Top