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

Wrap an entire element if it starts with text

Subject: Wrap an entire element if it starts with text
From: "Rick Quatro" <rick@xxxxxxxxxxxxxx>
Date: Tue, 22 Nov 2011 20:06:58 -0500
 Wrap an entire element if it starts with text
I have a series of <entry> elements whose entire contents I want to wrap in
a <p> element.

For example, here is before:

<entry>This is a raw entry that needs a p element.</entry>

Here is after:

<entry><p>This is a raw entry that needs a p element.</p></entry>

I want to ignore <entry> elements that already have a top-level child, like
this:

<entry><note>I don't want to add p to these.</note><entry>

I also want to ignore <entry> elements that just consist of a space, like
this:

<entry> </entry>

With my stylesheet and XPath statement below, everything works fine.
However, it doesn't handle elements like these, that also need to have their
contents wrapped:

<entry>This contains a nested <note>child</note> and I need these wrapped as
well.</entry>

I want to get this:

<entry><p>This contains a nested <note>child</note> and I need these wrapped
as well.</p></entry>

Any pointers or suggestions would be appreciated. Thank you very much.

Rick

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
version='1.0'>
  <xsl:template match="node() | @*">
    <xsl:copy>
       <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
  </xsl:template>
  <xsl:template match="//node()[parent::entry[not(*)][.!=' ']]">
    <xsl:element name="p">
      <xsl:copy>
         <xsl:apply-templates select="@* | node()"/>
      </xsl:copy>
    </xsl:element>
  </xsl:template>
</xsl:stylesheet>

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.