[xsl] Wrapping pieces of content separately

Subject: [xsl] Wrapping pieces of content separately
From: <Emily.Garrett@xxxxxxxxxxx>
Date: Fri, 25 Aug 2006 11:15:36 -0400
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.


To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
From: "Jay Bryant" <jay@xxxxxxxxxxxx>
Subject: Re: [xsl] Wrapping pieces of content separately
Message-ID: <000d01c6c7c1$5bf9a220$301d7446@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
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
that in the following stylsheet:

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

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

  <xsl:template match="doc">

  <xsl:template match="p[*]">

  <xsl:template match="p">

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

  <xsl:template match="ul">

  <xsl:template match="r">

  <xsl:template match="table">

  <xsl:template match="li">


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


Jay Bryant
Bryant Communication Services

Emily Garrett
Manager Production Tool Development
Thomson Global Production & Manufacturing
(513) 229-1526

Your past is not your potential.  In any hour you can choose to liberate
the future.

--Marilyn Ferguson

Current Thread