Re: [xsl] Test for PCDATA

Subject: Re: [xsl] Test for PCDATA
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Thu, 22 Feb 2001 22:35:56 +0000
Hi Marc,

> I need to be able to test for PCDATA from an element based on part of
> the string.
> need to have a test that determines something such as *_RCVD or
> *_SENT and then apply the appropriate style.

You need to use the string manipulation functions like substring() and
perhaps substring-after().  Let's say that the element you're testing
is something like:


You could test whether the 'foo' element ends with _RCVD with:

  substring(foo, string-length(foo) - 4) = '_RCVD'

Alternatively, you could test whether the part of the string after the
underscore ('_') equals 'RCVD' with:

  substring-after(foo, '_') = 'RCVD'

If you want to do a certain thing to foo elements for which this is
the case, then you can create a template that matches only those foo
elements and does something special to them:

<xsl:template match="foo[substring-after(., '_') = 'RCVD']">
   <!-- RCVD foo -->

If what you do to RCVD and SENT foo elements is largely the same, then
it's probably better to bung the code all in one foo-matching
template, and test within it just to change the bits that differ:

<xsl:template match="foo">
      <xsl:when test="substring-after(., '_') = 'RCVD'">
         <!-- RCVD-specific stuff -->
      <xsl:when test="substring-after(., '_') = 'SENT'">
         <!-- SENT-specific stuff -->
   <!-- general stuff -->

I hope that helps,


Jeni Tennison

 XSL-List info and archive:

Current Thread