Subject: Re: [xsl] Transforming XML Blockquotes - Mixed Content - XSLT 1.0 Solution From: JBryant@xxxxxxxxx Date: Thu, 14 Apr 2005 16:38:03 -0500 |
Forgive me for replying to my own post, but I developed a 1.0 solution to the problem. I also joined the two steps of my solution into one stylesheet. (By the way, ignore the key in my earlier XSL 2.0 solution. I was tinkering with a key-based solution and forgot to remove the line when I wrote the 2.0 solution.) Given this XML source: <doc> <paragraph num="1">Yadda Yadda Yadda <italic>Italic Yadda</italic> Yadda: <blockquote>Blah Blah Blah Blah</blockquote> Yackity Yack Yack</paragraph> </doc> And this XSL stylesheet: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:variable name="mixed"><xsl:apply-templates select="/" mode="unmix"/></xsl:variable> <xsl:template match="/"> <html> <head> <title>Paragraph Chunking Test</title> </head> <body> <xsl:for-each select="$mixed/p[not(preceding-sibling::*[1]/name()='p')]"> <xsl:variable name="group" select="@group"/> <p num="{@num}"> <xsl:for-each select="../p[@group=$group]"> <xsl:apply-templates/> </xsl:for-each> </p> <xsl:apply-templates select="following-sibling::blockquote"/> </xsl:for-each> </body> </html> </xsl:template> <xsl:template match="paragraph/text()" mode="unmix"> <p num="{../@num}" group="{count(preceding-sibling::blockquote)}"><xsl:value-of select="."/></p> </xsl:template> <xsl:template match="blockquote" mode="unmix"> <blockquote><xsl:apply-templates/></blockquote> </xsl:template> <xsl:template match="italic" mode="unmix"> <p num="{../@num}" group="{count(preceding-sibling::blockquote)}"><span style="font-style:italic"><xsl:apply-templates/></span></p> </xsl:template> <xsl:template match="p"/> <xsl:template match="blockquote"> <xsl:copy-of select="."/> </xsl:template> <xsl:template match="span"> <xsl:copy-of select="."/> </xsl:template> </xsl:stylesheet> I get the following result: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Paragraph Chunking Test</title> </head> <body> <p num="1">Yadda Yadda Yadda <span style="font-style:italic">Italic Yadda</span> Yadda: </p> <blockquote>Blah Blah Blah Blah</blockquote> <p num="1"> Yackity Yack Yack</p> </body> </html> Jay Bryant Bryant Communication Solutions (presently consulting at Synergistic Solution Technologies)
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Transforming XML Blockquo, JBryant | Thread | Re: [xsl] Transforming XML Blockquo, David Carlisle |
Re: [xsl] Total number of pages wit, Jirka Kosek | Date | Re: [xsl] Transforming XML Blockquo, David Carlisle |
Month |