[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Transforming XML Blockquotes - Mixed Content - XSL

Subject: Re: Transforming XML Blockquotes - Mixed Content - XSLT 1.0 Solution
From: JBryant@xxxxxxxxx
Date: Thu, 14 Apr 2005 16:38:03 -0500
xslt mixed content
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.