This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: for-each -- strange multiplication effects
- To: xsl-list at lists dot mulberrytech dot com
- Subject: Re: [xsl] for-each -- strange multiplication effects
- From: David Carlisle <davidc at nag dot co dot uk>
- Date: Tue, 16 Jan 2001 13:49:27 GMT
- CC: elke dot e dot meier at daimlerchrysler dot com
- References: <0057440003355118000002L482*@MHS>
- Reply-To: xsl-list at lists dot mulberrytech dot com
> 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