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

Re: Test for PCDATA

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

> I need to be able to test for PCDATA from an element based on part of
> the string.
>
> If is have PCDATA such as TOC_RCVD, TOC_SENT, REQ_RCVD,REQ_SENT....I
> 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:

  <foo>TOC_RCVD</foo>

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 -->
   ...
</xsl:template>

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:choose>
      <xsl:when test="substring-after(., '_') = 'RCVD'">
         <!-- RCVD-specific stuff -->
      </xsl:when>
      <xsl:when test="substring-after(., '_') = 'SENT'">
         <!-- SENT-specific stuff -->
      </xsl:when>
   </xsl:choose>
   <!-- general stuff -->
</xsl:template>

I hope that helps,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.