Subject: Selecting nodes that have an attribute
From: Garrett Coakley <gc@xxxxxxxxxxxxxxxx>
Date: Fri, 27 Aug 1999 17:30:26 +0100 (GMT Daylight Time)
|
Hi all,
I'm trying to select a series of nodes, only if they have a certain
attribute (called yearend). This is a snippet of the XML
<ESTIMATES>
<ESTIMATE>
<ANNUALFORECAST yearend="12/1999F">
<ESTIMATEDATA>
<SALES name="Sales">25</SALES>
</ESTIMATEDATA>
</ANNUALFORECAST>
<ANNUALFORECAST yearend="12/2000F">
<ESTIMATEDATA>
<SALES name="Sales">27</SALES>
</ESTIMATEDATA>
</ANNUALFORECAST>
</ESTIMATE>
<ESTIMATE>
<ANNUALFORECAST>
<ESTIMATEDATA>
<SALES>25</SALES>
</ESTIMATEDATA>
</ANNUALFORECAST>
<ANNUALFORECAST>
<ESTIMATEDATA>
<SALES>27</SALES>
</ESTIMATEDATA>
</ANNUALFORECAST>
</ESTIMATE>
</ESTIMATES>
And this is the XSL:
<xsl:template match="ESTIMATES">
<xsl:for-each select="ESTIMATE/ANNUALFORECAST[@yearend]">
<TD COLSPAN="5">
<xsl:value-of select="@yearend"/>
</TD>
</xsl:for-each>
I thought that the 'for-each' I have on the second line would only
select ANNUALFORECAST where it had a yearend attribute, but the HTML
that is being produced has a number of extra (empty) table cells. Which
funnily enough corresponds to the total amount of ANNUALFORECAST's in
the branch.
I've been banging my head against this problem for a couple of days now,
and it's got to the stage where I probably couldn't see the right answer
if it landed on my desk in a gold sequinned ballgown.
Have I seriously missed something in the XSLT spec?
Thanks for any help or pointers.
Garrett.
--
-----------------------------------------------------------
Garrett Coakley | "A man's friendships are one of
Design Engineer | the best measures of his worth."
www.community.co.uk | Charles Darwin
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|