Subject: Re: [xsl] for-each -- strange multiplication effects From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx> Date: Tue, 16 Jan 2001 13:57:43 +0000 |
Hi Mario, > When the predicate is true for one element that matches the node set > (say "//x") specified by the select attribute of for-each it it > repeated count(//x) times even when the predicate is false. > > <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> In your template, you're matching 'test' elements. When templates are applied to the 'doc' element, then the built-in template is used, and templates are applied to *all* the 'test' elements (4 of them). Each time the processor comes across one of these test elements (which it does 4 times), it goes through all the 'test' elements with a 'x' attribute (1 of them) and outputs the content. To get the effect that you want, try the following: <xsl:template match="doc"> <xsl:for-each select="//test[@x]"> this should only happen once! <xsl:value-of select="@x"/> </xsl:for-each> </xsl:template> This template will only be applied once, because there's only one 'doc' element in the source XML. Alternatively, use: <xsl:template match="test[@x]"> this should only happen once! <xsl:value-of select="@x"/> </xsl:template> This template will only be applied once, because there's only one 'test' element with an 'x' attribute. I hope that helps, Jeni --- Jeni Tennison http://www.jenitennison.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] for-each -- strange multi, David Carlisle | Thread | [xsl] Re: for-each -- strange multi, Dimitre Novatchev |
Re: [xsl] select="substring-before(, Dimitre Novatchev | Date | Re: [xsl] select="substring-before(, David Carlisle |
Month |