This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: position()



> Well yes, but I would have thought that xsl like

you didn't show the only part of your XSL that matters.
Namely the command that constructs the current node list.
position() counts the position of the current node in the current node
list. It isn't directly tied to the input document or the currently
active template. 

given

<objects>
	<!-- hello -->
	<object name="first"/>
	<object name="second"/>
	<!-- hello -->
	<object name="third"/>
	<object name="fourth"/>
</objects>


if you go <xsl:apply-templates/> then you default to select="node()"
and so the current list is
1 white space
2 comment
3 white space
4 object
5 white space
6 object
...

unless you specified in your stylesheet that white space should be
stripped (or you use MSXML3 which takes a "liberal" reading of the spec on
this point)


If you only want object nodes in your list just select those and have
<xsl:apply-template select="object">

then you get a list
1 object
2 object
...

> Also on a related point how can I output the preceding node if and
> only if it is a comment.

<xsl:copy-of select="preceding::*[1][self::comment()]"/>

David


_____________________________________________________________________
This message has been checked for all known viruses by Star Internet delivered
through the MessageLabs Virus Control Centre. For further information visit
http://www.star.net.uk/stats.asp

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]