xsl-list
[Top] [All Lists]

[xsl] Wrapping pieces of content separately

2006-08-25 08:15:41

Hi, Jay,
I can't thank you enough for your solution. It works like a charm. I
have been wracking my brain for days on this.

Emily

To: <xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
From: "Jay Bryant" <jay(_at_)bryantcs(_dot_)com>
Subject: Re: [xsl] Wrapping pieces of content separately
Message-ID: <000d01c6c7c1$5bf9a220$301d7446(_at_)jayb>

Hi, Emily,

As it happens, I've solved this problem in the past. The trick to is
processing text nodes according to their context. If a p element has
children other than text nodes, then you don't want that p element to be
a p
element; you want it to be a series of elements. If a p element has just
text nodes (which really means just one text node, but that doesn't
matter),
then it should end up in a p element

The way to do it is to catch the text nodes of p elements that have
non-text-node children and wrap those text nodes in p elements. I've
done
that in the following stylsheet:

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

  <xsl:output method="xml" indent="yes"/>

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

  <xsl:template match="p[*]">
    <xsl:apply-templates/>
  </xsl:template>

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

  <xsl:template match="text()[parent::p[*]]">
    <p><xsl:value-of select="."/></p>
  </xsl:template>

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

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

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

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

</xsl:stylesheet>

I got the desired output when I applied this stylesheet to your input
(after
I corrected it to have a document element and a closing tag for the ul
element).

HTH

Jay Bryant
Bryant Communication Services

Emily Garrett
Manager Production Tool Development
Thomson Global Production & Manufacturing
(513) 229-1526
emily(_dot_)garrett(_at_)thomson(_dot_)com
 
Your past is not your potential.  In any hour you can choose to liberate
the future.

--Marilyn Ferguson



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>