[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
My silly mistake. The template modes don't match. D'oh.
<xsl:apply-templates select="//players/player" mode="PositionList" />
<xsl:template match="player[not(position= preceding::position/.)]"> mode="positionList">
I believe that is what they refer to as a schoolboy error ;)
Gareth, SBE
-----
Gareth Howells
Grey College JCR
IT Officer and Technical Services Manager
University of Durham
07862725134
----- Original Message ----- From: "Gareth Howells" <subscriptions@xxxxxxxxxxxxxxxxxxxxxxx>
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Friday, November 30, 2007 9:34 PM
Subject: [xsl] Problem with xsl:template using XSLT 1.0
Re: [xsl] Problem with xsl:template using XSLT 1.0
Subject: Re: [xsl] Problem with xsl:template using XSLT 1.0 From: "Gareth Howells" <subscriptions@xxxxxxxxxxxxxxxxxxxxxxx> Date: Tue, 4 Dec 2007 13:04:11 -0000 |
My silly mistake. The template modes don't match. D'oh.
<xsl:apply-templates select="//players/player" mode="PositionList" />
<xsl:template match="player[not(position= preceding::position/.)]"> mode="positionList">
I believe that is what they refer to as a schoolboy error ;)
Gareth, SBE
-----
Gareth Howells
Grey College JCR
IT Officer and Technical Services Manager
University of Durham
07862725134
----- Original Message ----- From: "Gareth Howells" <subscriptions@xxxxxxxxxxxxxxxxxxxxxxx>
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Friday, November 30, 2007 9:34 PM
Subject: [xsl] Problem with xsl:template using XSLT 1.0
Hello all,
First off, thanks to everyone who replied with suggestions to my query regarding converting a string to upper or lower case. Unfortunately due to an email issue I have been unable until now to post back to the group. Thanks again for all your suggestions.
My query this time is regarding the use of xsl:template and xsl:apply-templates instead of using xsl:for-each loops.
First off, a little bit of background - I am required to extract data from an XML regarding a fantasy football league. The data I am interested in in this instance is a list of all of the clubs from which there are players in the league, and a list of the positions in which they play, with duplicates removed using the predicates not(club= preceding::club/.) and not(position= preceding::position/.). The structure of the data in the XML file is as follows:
fantasy/players/player
with each player element having
@pid name club value position
I am trying to display a pair of unordered lists, one containing the clubs with duplicates removed, one containing the positions with duplicates removed. I am using unordered lists because I would prefer to use bullet points rather than numbered items, however I am using xsl:sort to sort the data into alphabetical order.
I currently have a working stylesheet which uses xsl:for-each to achieve this, the relevant code reading as follows:
<ul> <xsl:for-each select="//players/player[not(club= preceding::club/.)]<xsl:sort select="club" order="ascending" /> <li><xsl:value-of select="club" /></li> </xsl:for-each> </ul>
<ul> <xsl:for-each select="//players/player[not(position= preceding::position/.)]"> <xsl:sort select="position" order="ascending" /> <li><xsl:value-of select="position" /></li> </xsl:for-each> </ul>
As I say, that works perfectly. However it is a requirement for my coursework that I use templates rather than for-each loops. I can only assume that my understanding of templates is flawed, because while I can get very basic examples to work, I just can't seem to get this to work. The code I am using is as follows (so far I've only implemented the positions list using templates):
<ul> <xsl:apply-templates select="//players/player" mode="PositionList" /> </ul>
within <xsl:template match="/"> </xsl:template>, followed by the template definition:
<xsl:template match="player[not(position= preceding::position/.)]" mode="positionList"> <xsl:sort select="position" order="ascending" /> <li><xsl:value-of select="position" /></li> </xsl:template>
For some reason, what's generated is a <ul> element containing the values of each of the four child elements of player, with no <li> elements at all, an example taken from the HTML source code generated:
<ul> J Lehmann ARS 4.4 Goalkeeper
M Almunia ARS 4.1 Goalkeeper
J Aghahowa WIG 5.7 striker
D Cotterill WIG 5.3 striker </ul>
Can anyone suggest what I might be doing wrong? Apologies if this mail is a little long. If you need the entire source for the XSL page, let me know.
Thanks in advance, Gareth DMU
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Problem with xsl:template, Andrew Welch | Thread | Re: [xsl] Dumb Question - XML to XM, Mukul Gandhi |
Re: [xsl] Outputing PDF, Alice Wei | Date | RE: [xsl] Outputing PDF, cknell |
Month |