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

Wrapping pieces of content separately

Subject: Wrapping pieces of content separately
From: <Emily.Garrett@xxxxxxxxxxx>
Date: Fri, 25 Aug 2006 11:15:36 -0400
 Wrapping pieces of content separately
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@xxxxxxxxxxxxxxxxxxxxxx>
From: "Jay Bryant" <jay@xxxxxxxxxxxx>
Subject: Re:  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
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.garrett@xxxxxxxxxxx

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

--Marilyn Ferguson

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.