Subject: Re: Passing element nodes through string functions (WAS RE: [xsl] Preserving inline elements when using string functions) From: David Carlisle <davidc@xxxxxxxxx> Date: Tue, 26 Aug 2003 23:18:36 +0100 |
I wrote: > it's a grouping problem (positional grouping in Mike's terminoligy) > you want to group all child nodes before or after text nodes containing > cr ie text()[contains(.,' ')] you need to work at the level of nodes > not of the entire content of your bodytext element. > > See Jeni's site on grouping techniques. > > David I suppose this is probably more helpful... div.xml ======== <page> <bodytext>This is the <link url="zzz">link</link> This is another line</bodytext> </page> div.xsl ======== <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:key name="x" match="bodytext/node()" use="generate-id((..|preceding-sibling::text()[contains(.,' ')][1])[last()])"/> <xsl:template match="page"> <html> <head> <title>testing...</title> </head> <xsl:apply-templates/> </html> </xsl:template> <xsl:template match="link"> <a href="{@url}"> <xsl:apply-templates/> </a> </xsl:template> <xsl:template match="bodytext"> <body> <xsl:for-each select=".|text()[contains(.,' ')]"> <div> <xsl:value-of select="substring-after(self::text(),' ')"/> <xsl:apply-templates select="key('x',generate-id(.))[position()<last()]"/> </div> <xsl:value-of select="substring-before(key('x',generate-id(.))[last()],' ')"/> </xsl:for-each> </body> </xsl:template> </xsl:stylesheet> $ saxon div.xml div.xsl <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>testing...</title> </head> <body> <div>This is the <a href="zzz">link</a></div> <div> This is another line</div> </body> </html> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: Passing element nodes through s, David Carlisle | Thread | Re: Passing element nodes through s, David Carlisle |
Re: [xsl] character entity referenc, Elliotte Rusty Harol | Date | RE: [xsl] treating <xsl:value-of..>, Michael Kay |
Month |