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: for-each -- strange multiplication effects



> this should only happen once!

It does only happen once.

That is, each time you execute <xsl:for-each select="//test[@x]">
only one node is selected.

However you  have this in the template for test and you haven't any
other templates defined so you get the default template applied
for the root "/"

this just applies templates to the children of /.

You haven't a template for doc so the default is again applied,
and again templates are applied to each of the child nodes.

So your template is then applied to each of the test nodes.
As your template for test is

<xsl:template match="test">
	<xsl:for-each select="//test[@x]">
		this should only happen once!
		<xsl:value-of select="@x"/>
	</xsl:for-each>
</xsl:template>


The result it generates does not depend on the actual node matched
(the body of the template always searches the whole document again for
test nodes) so you get the same output for each test node selected.

Probably what you meant to have was


<?xml version="1.0" encoding="UTF-8"?>
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" encoding="UTF-8"/>

<xsl:template match="test[@x]">
		this should only happen once!
</xsl:template>


<xsl:template match="test"/>

</xsl:transform>


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]