[Home] [By Thread] [By Date] [Recent Entries]

and the error I get is "Reference to variable or parameter 'mixed' must 
evaluate to a node list."

------------------------------------------------------------------------

My bad. Please accept my apologies. As David C. and Wendell both caught me 
on, I had used an XSLT 2.0 processor for an XSLT 1.0 project and had 
inadvertently rolled in a couple XSLT 2.0 features that your processor is 
now catching. Here's a pair of stylesheets that correct the problems:

As you may recall, my method (in among all the madness) was to first turn 
this into a grouping problem and then to solve the grouping problem. So, 
this first stylesheet turns your mixed content problem into a grouping 
problem by turning each child node of the paragraph except for the 
blockquote into its own paragraph element.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:template match="/">
    <x>
      <xsl:apply-templates/>
    </x>
  </xsl:template>

  <xsl:template match="paragraph">
    <xsl:apply-templates/>
  </xsl:template>

  <xsl:template match="paragraph/text()">
    <p num="{../@num}" 
group="{count(preceding-sibling::blockquote)}"><xsl:value-of 
select="."/></p>
  </xsl:template>

  <xsl:template match="blockquote">
    <blockquote><xsl:apply-templates/></blockquote>
  </xsl:template>

  <xsl:template match="italic">
    <p num="{../@num}" 
group="{count(preceding-sibling::blockquote)}"><span 
style="font-style:italic"><xsl:apply-templates/></span></p>
  </xsl:template>

</xsl:stylesheet>

When I run it with Xalan-J 2.4.1 (an XSLT 1.0 processor), I get:

<?xml version="1.0" encoding="UTF-8"?>
<x>
  <p group="0" num="1">Yadda Yadda Yadda </p>
  <p group="0" num="1">
  <span style="font-style:italic">Italic Yadda</span></p>
  <p group="0" num="1"> Yadda: </p>
  <blockquote>Blah Blah Blah Blah</blockquote>
  <p group="1" num="1"> Yackity Yack Yack</p>
</x>

This second stylesheet solves the grouping problem:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:template match="x">
    <html>
      <head>
        <title>Paragraph Chunking Test</title>
      </head>
      <body>
        <xsl:for-each select="p[not(preceding-sibling::*[1]/self::p)]">
          <xsl:variable name="group" select="@group"/>
          <p>
            <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="p"/>

  <xsl:template match="blockquote">
    <xsl:copy-of select="."/>
  </xsl:template>

  <xsl:template match="span">
    <xsl:copy-of select="."/>
  </xsl:template>

</xsl:stylesheet>

Applied to the result of the first stylesheet, it produces (again with 
Xalan-J 2.4.1) the following output:

<html>
  <head>
    <META http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Paragraph Chunking Test</title>
  </head>
  <body>
    <p>Yadda Yadda Yadda <span style="font-style:italic">Italic 
Yadda</span> Yadda: </p>
    <blockquote>Blah Blah Blah Blah</blockquote>
    <p> Yackity Yack Yack</p>
  </body>
</html>

Thank you for your patience. Also, thanks to Wendell and David C. for 
their constant instruction.

Jay Bryant
Bryant Communication Services
(presently consulting at Synergistic Solution Technologies)

Current Thread
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member