Altova Mailing List Archives

Re: [xsl] Transforming XML Blockquotes - Mixed Content

From: James Fuller <jim.fuller@-------------->
Date: 4/14/2005 1:11:00 AM
Wendell Piez wrote:

> Right. And (sadly) some of us old-timers sighed when we saw the post,
> because we knew (a) the problem wasn't easy, and (b) most attempts to
> handle it deal only with a subset of the actual problem (as you have
> noticed). This is usually okay in practice (often one only *has* a
> subset of the problem), but does require more fine-grained analysis of
> requirements, such as

Wendell is spot on....and this type of problem is probably the largest
use case that XSLT struggles with....

here is another possible approach to solving the problem using  a 2
stage transformation (i have used variables  so its easy to illustrate
the process)....


<?xml version="1.0" encoding="ISO-8859-1" ?>
    Yadda Yadda Yadda <italic>Italic Yadda</italic> Yadda:
        <blockquote>Blah Blah Blah Blah</blockquote>
        Yackity <font>Yack</font> Yack and wh


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"

  <xsl:variable name="list-of-elements" select="'italic font'"/>
  <xsl:template match="root">

    <!-- 1st step: admittedly weird kind of tokenization with <p> -->
    <xsl:variable name="result">
    <!-- 2nd step: create new tree -->
    <xsl:variable name="final">
     <xsl:apply-templates select="$result" mode="final"/>

    <!-- 3rd step: print out result -->
    <xsl:copy-of select="$final"/>

  <xsl:template match="text()">
    <xsl:if test="normalize-space()">
      <p><xsl:value-of select="normalize-space(.)"/></p>
  <xsl:template match="*[contains($list-of-elements,name())]">
    <xsl:copy-of select="."/>
  <xsl:template match="blockquote"><xsl:copy-of
  <xsl:template match="*[contains($list-of-elements,name())]" mode="final">
      <xsl:value-of select="preceding-sibling::node()[1]"/>
      <xsl:element name="{name()}">
        <xsl:value-of select="."/>
      <xsl:value-of select="following-sibling::node()[1]"/>
and following-sibling::node()[not(contains($list-of-elements,name()))]]"

  <xsl:template match="p" mode="final">
and following-sibling::node()[not(contains($list-of-elements,name()))]">
      <xsl:copy-of select="."/>

  <xsl:template match="blockquote"  mode="final"><xsl:copy-of

not tested, and pretty ugly

gl, Jim Fuller


These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.