You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by bSpot <bl...@bspot.de> on 2003/11/06 01:06:28 UTC

Hello & s.t. about last()

High everyone,

first, as this is my first mail to this list, I justed wanted to say 'Hello!' 
to everyone and ask you politely to remain patient and calm in dealing with 
me in the future... So far, I've got my fair share of experience in 
programing and some related standards, but I know as good as nothing about 
XML and possibly even less about XSLT.

Okay, to avoid becoming guilty of off-topic posting, here's the first funny 
thing I encountered playing around with Xalan (Java Version 2.5.2 and 
Xerces-J 2.40 as far as it matters):

Transforming this XML:

	<entrylist>
		<entry flag="yes">one</entry>
		<entry flag="no">two</entry>
		<entry>three</entry>
		<entry flag="no">four</entry>
		<entry flag="yes">five</entry>
		<entry flag="no">six</entry>
		<entry>seven</entry>
	</entrylist>

using this stylesheet (fragment):

	<xsl:template match="entrylist">
		<this_one_works>
			<xsl:apply-templates 
				select="entry[@flag='yes' or not(@flag)]"/>
		</this_one_works>
		<this_one_doesnt>
			<xsl:apply-templates
				select="entry[@flag='yes']|entry[not(@flag)]"/>
		</this_one_doesnt>
	</xsl:template>
	
	<xsl:template match="entry">
		<xsl:value-of select="."/>
		<xsl:if test="position()!=last()">, </xsl:if>
	</xsl:template>

yields this result:

	<this_one_works>one, three, five, seven</this_one_works>
	<this_one_doesnt>one, </this_one_doesnt>

Which is quite funny, I think - as I consider, the output from the two 
xsl:apply-templates should be equal. Even more funny is, that they _get_, if 
I remove the xsl:if inserting the commata. And as it seems, it is the call to 
last() which breaks the current selection, because the same problem occurs, 
if I just _call_ last() within the second template, i.e. by
	<xsl:value-of select="last()"/>

I don't know what that means. If it's some kind of bug it might not be too 
severe, as the two used expressions are pretty equivalent and there's no need 
to use the latter, but it would be sure nice to know if I'm stupid this time 
or if it's the machine.

Well.. I'm off.

best regards
	bSpot