Re: [xsl] Testing Text

Subject: Re: [xsl] Testing Text
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Wed, 07 Jan 2009 12:11:44 -0500

At 06:32 AM 1/7/2009, David wrote:
pases the current node to a string function, so the function argument is
the string value of the node, which is all the character data of the

You want something like

<xsl:template match="*">
      <xsl:if test="contains(text(),'@')">@ found in <xsl:value-of

... but beware, this is brittle when faced with mixed content ... test="text()[contains(.,'@')]" is somewhat less so ...


<xsl:template match="text()">
      <xsl:if test="contains(.,'@')">@ found in <xsl:value-of

This is better, and will generally work.

But if you have cases like

<p>Here's my @ text</p>
<p>Here's my <i>extra special @</i> text</p>

and always want to report "@ found in p" and never "@ found in i", you've got a different problem on your hands. :-)


Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.      
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