From: Michael Kay [mailto:mike(_at_)saxonica(_dot_)com]
Sent: 30 September 2008 16:28
Subject: RE: [xsl] Implementing a (fairly) complex business rule
If you're using data-oriented XML with element-only content (no mixed
content, no comments or processing-instructions) then the only time
you might use text() is in a conditional: <xsl:if
test="MIDDLE_NAME/text()"> which will be false if there is no
MIDDLE_NAME element or if there is a MIDDLE_NAME element and it is
empty (more strictly, if every MIDDLE_NAME child of the context node
is empty). But I prefer to write this as test="string(MIDDLE_NAME)",
or as test="normalize-space(MIDDLE_NAME)" if I also want to exclude
the case where the value exists but contains whitespace.
A special case is what one might call "abnormal mixed content", where
the structure is that of mixed content but the semantics are
unorthodox: for example
(It would be more usual to use attributes here rather than child
elements; but one also sees comments used.) In such a case you may
need to find the text node (or all the text nodes) explicitly using
I can't thank you guys enough. I feel I have a much better
As I've said, the stuff here is all data-oriented, so we don't have to
worry about mixed content or anything like that.
For now, I'm doing this for the <POSTCODE> element:
<!-- NULL is valid for a postcode -->
/s0:REDUCEDI = '00'">
<xsl:if test="s0:DOMICILE='XF' or s0:DOMICILE='XG' or s0:DOMICILE='XH'
or s0:DOMICILE='XI' or s0:DOMICILE='XK' or s0:DOMICILE='XL' or
s0:DOMICILE='GG' or s0:DOMICILE='JE' or s0:DOMICILE='IM'">
I guess that the text() in <xsl:value-of select="s0:POSTCODE/text()"/>
is redundant, but everything appears to be working, so using the, "If it
ain't broke don't fix it" rule, I've left it in.
We'll know better next time.
My next step is to do an audit of the elements where we've used the
string-length() test, and to change them where necessary.
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>