|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Test for 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








