Subject: RE: [xsl] from start tag A to end tag B From: "Robert Soesemann" <rsoesemann@xxxxxxxxxxx> Date: Mon, 31 Jan 2005 17:25:02 +0100 |
That is perfectly what I was looking for. Her is the final code with some adjustments to my real world case. The only problem that I now have is that I get all the node inside <textItem> in the opposite order. How can I prevent the xsl from doing this? <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:key name="x" match="node()" use="generate-id((self::p[@class='headline_04']|preceding-sibling::p[@cl ass='headline_04'])[last()])"/> <xsl:template match="/ | @* | node()"> <xsl:copy> <xsl:apply-templates select="@* | node()"/> </xsl:copy> </xsl:template> <xsl:template match="attribute[@markup='yes']"> <xsl:for-each select="p[@class='headline_04']"> <textItem> <xsl:copy-of select="key('x',generate-id())"/> </textItem> </xsl:for-each> </xsl:template> </xsl:stylesheet> -----Original Message----- From: David Carlisle [mailto:davidc@xxxxxxxxx] Sent: Montag, 31. Januar 2005 17:01 To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: Re: [xsl] from start tag A to end tag B > I do not understand how to do that. jeni's site will explain how to use grouping based on "content" but in your case the content is not a text string from element or attribute content but rather the node identity of the nearest p node with a foo class. generate-id returns a unique string for each node, so once you have that string you just use the usual grouping idioms. Note there are alternative mechanisms, eg Joris has just answered an almost identical question in the parallel Re: [xsl] Grouping immediate follow sibling thread, giving two other strategies. David this works on your input: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:key name="x" match="root/node()" use="generate-id((self::p[@class='foo']|preceding-sibling::p[@class='foo '])[last()])"/> <xsl:template match="root"> <xsl:for-each select="p[@class='foo']"> <textitem> <xsl:copy-of select="key('x',generate-id())"/> </textitem> </xsl:for-each> </xsl:template> </xsl:stylesheet> ________________________________________________________________________ This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk ________________________________________________________________________
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] from start tag A to end t, David Carlisle | Thread | Re: [xsl] from start tag A to end t, David Carlisle |
RE: [xsl] xalan-j - outputing html , Michael Kay | Date | Re: [xsl] xalan-j - outputing html , Kevin Rodgers |
Month |