Click to See Complete Forum and Search --> : Help with counting nodes plz


baz7621
03-15-2005, 01:53 PM
Hiya All!
I am trying to get a very simple count function to work but cant maybe someone can help

I have a xml page laid out as


<SPEECH>
<SPEAKER>PUCK</SPEAKER>
<LINE>How now, spirit! whither wander you?</LINE>
</SPEECH>


And in my xsl page I been trying stuff like

<xsl:value-of select="count(SPEECH[$speaker]/LINE)" />

and

<xsl:value-of select="count(SPEECH[./SPEAKER[PUCK]]//LINE" />


where $speaker is the variable, which I know does work. Even replacing $speaker with PUCK or
'PUCK' doesn't work. The aim being to return a value of "1", if I were to use the above XML.

This is all being done within a template matching "SCENE", where SCENE is the immediate parent of SPEECH.
Can anyone help? It is only so that I can put it within a choose statement to say that if the line count for a certain speaker is equal to zero, then it will display "Does not appear" in the scene.


Thanks In advance

crh3675
03-15-2005, 04:11 PM
Did you try"


<xsl:value-of select="count(/SPEECH[SPEAKER='PUCK']/LINE)" />

baz7621
03-15-2005, 05:12 PM
yep so no luck any other ideas

crh3675
03-15-2005, 06:07 PM
Okay, you say SCENE is the parent of SPEECH. Then add a .:


<xsl:value-of select="count(./SPEECH[SPEAKER='PUCK']/LINE)" />

Khalid Ali
03-15-2005, 09:07 PM
this will return 1

<xsl:value-of select="count(SPEECH/LINE)" />

the way u are trying to reference, it implies that speech has an element($speaker) and this variable has a cchild element name line which is wrong(according to the xml u posted)
LINE is a direct child of SPEECH ,hence it should be referenced accordingly.