Subject: [xsl] concatenating ranges of nodes From: "James Carlyle" <james.carlyle@xxxxxxxxxx> Date: Thu, 20 Sep 2001 21:52:09 +0100 |
Help for a beginner, please I am processing html passed through Tidy, and am processing structural html elements and text nodes. Here is an example of input and current output: --- Input --- <html> <body> <div> Hey diddle <b>diddle</b> <div> the cat and the <b>fiddle</b> </div> The cow jumped <a href="abc">over</a> the moon </div> </body> </html> --- Output --- <block tag="html"> <block tag="body"> <block tag="div"> <text>Hey diddle </text> <text>diddle</text> <block tag="div"> <text>the cat and the </text> <text>fiddle</text> </block> <text> The cow </text> <text>jumped</text> <link><href>abc</href><text>over</text></link> <text> the moon</text> </block> </block> </block> My stylesheet currently looks like: <xsl:template match="/"> <xsl:apply-templates/> </xsl:template> <xsl:template match="html|body|p|table|tr|td|div|dd|dt|dl|ul|ol|li|br|nobr"> <block> <xsl:apply-templates /> </block> </xsl:template> <xsl:template match="a"> <link> <href><xsl:value-of select="@href"/></href> <text><xsl:value-of select="."/></text> </link> </xsl:template> <xsl:template match="text()"> <text> <xsl:value-of select="."/> </text> </xsl:template> I want to concatenate any adjoining <text> elements in the output, to produce the following: --- Output --- <block tag="html"> <block tag="body"> <block tag="div"> <text>Hey diddle diddle</text> <block tag="div"> <text>the cat and the fiddle</text> </block> <text> The cow jumped</text> <link><href>abc</href><text>over</text></link> <text> the moon</text> </block> </block> </block> I can't think of a way of concatenating text nodes within the single stylesheet. I've experimented with an intersection of node sets, seeing if I can delay writing out a single <text> elements just before writing out <block>, </block> or <link>, and taking the intersection of text nodes looking forward from the previous start point and backwards from the current node. I've also tried numbering previous start points and the current node, and picking out all text nodes numbered in this range. I'm hoping that someone on this list thinks that this is a trivial problem - I ceased to see the wood from the trees several hours ago. Many thanks if you can help. James Carlyle XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] template match syntax - p, Michael Kay | Thread | Re: [xsl] concatenating ranges of n, David Carlisle |
Re: [xsl] one XML file, two XSLT st, Jörg Heinicke | Date | Re: [xsl] concatenating ranges of n, David Carlisle |
Month |