Re: [xsl] Comparing with a variable position

Subject: Re: [xsl] Comparing with a variable position
From: Joerg Heinicke <joerg.heinicke@xxxxxx>
Date: Thu, 10 Oct 2002 09:18:09 +0200
Hello Louis,

Louis Meigret wrote:
----- Original Message -----
From: "Joerg Heinicke" <joerg.heinicke@xxxxxx>

Thank you Jörg, this seems elegant, two questions though.

<xsl:template match="node()|@*">
    <xsl:apply-templates select="node()|@*"/>

1) Why the above template rather than the simpler
<xsl:template match="container">, I'm especially puzzled by the <xsl:copy> (I'm a newbie).

this is a template, that copies everything node by node (or attribute by attribute) to the output. It's called identity transformation and can also be found in the spec: I have used it, because you don't want only to copy <container/>, but also everything between the separators to the output.

<xsl:template match="container/text()">
    <xsl:value-of select="."/>

<xsl:template match="separator"/>

If "thus several node are possible" instead of text "mixed content"

2) Well I do not know if it is "instead", I meant "or". Is mixed content contardictory with several nodes (text and elements)?

That's ok. A text node is also a node of course. node() includes text(), comment(), processing-instruction() and elements.

So for your problem we need the grouping. It's called Muenchian Method and you will find it quite often in the archives or at

<xsl:key name="nodes-by-sep" match="container/node()[not(self::separator)]" use="generate-id(following-sibling::separator)"/>

<xsl:template match="container">
<xsl:apply-templates select="node()[generate-id() = generate-id(key('nodes-by-sep', generate-id(following-sibling::separator)))]"/>

<xsl:template match="container/node()">
<xsl:copy-of select="key('nodes-by-sep', generate-id(following-sibling::separator))"/>

Here identity transformation is not used anymore, but it's possible. If you replace the <xsl:copy-of/> in the last template with <xsl:apply-templates/> (select attribute is the same), the nodes are copied node by node and not the whole subtree at once. Maybe you need it, if you want to further process the subtree.

And a question to your XML source. Isn't it possible to change this, so that you don't need this grouping? I don't know where it comes from, but if it's an output of anything, can this anything not output <sub-container/>s too instead of separators?



XSL-List info and archive:

Current Thread