|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Comparing with a variable position
Hello Louis,
Louis Meigret wrote: ----- Original Message ----- From: "Joerg Heinicke" <joerg.heinicke@xxxxxx> 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: http://www.w3.org/TR/xslt#copying. I have used it, because you don't want only to copy <container/>, but also everything between the separators to the output.
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 http://www.jenitennison.com/xslt/grouping/muenchian.xml. <xsl:key name="nodes-by-sep" match="container/node()[not(self::separator)]" use="generate-id(following-sibling::separator)"/> <xsl:template match="container"> <xsl:copy> <xsl:apply-templates select="node()[generate-id() = generate-id(key('nodes-by-sep', generate-id(following-sibling::separator)))]"/> </xsl:copy> </xsl:template> <xsl:template match="container/node()"> <sub-container> <xsl:copy-of select="key('nodes-by-sep', generate-id(following-sibling::separator))"/> </sub-container> </xsl:template> 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? Regards, Joerg XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








