Re: [xsl] Extracting text

Subject: Re: [xsl] Extracting text
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Wed, 25 May 2005 19:08:32 -0400
Jon,

Ordinarily, one would do this implicitly by way of the default traversal, as in simply

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

<xsl:template match="span | br"/>
<!-- this template suppresses the span and br -->

If you do this you'll find your text is "extracted".

In particular cases, one might be more explicit about the extraction:

<xsl:template match="p">
  <xsl:apply-templates select="text()"/>
  <!-- this instruction selects only text node children
       and processes them -->
</xsl:template>

... but not uncommonly when we see this sort of thing, it's an indication of either bad coding in the XSLT, bad design of the source XML, or both. Yet you can certainly do it, and might even have a good reason to.

I hope this helps,
Wendell

At 06:31 PM 5/25/2005, you wrote:
'lo all,

I need to extract
  'Root level text'
  'more root level text'

from:

<p>
  <span>whatever</span>
  Root level text
  <br/>
  more root level text
</p>

Any ideas?

Thanks, jon
jopaki@xxxxxxxxx





__________________________________
Do you Yahoo!?
Yahoo! Small Business - Try our new Resources site
http://smallbusiness.yahoo.com/resources/


======================================================================
Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================

Current Thread