It's better to do it without the Result Tree Fragment as intermediate step:

<xsl:variable name="xtest" select="department"/>

Is the variable needed? You can of course directly test on the element:

<xsl:if test="string(department)">
  is true if any character is contained in <department/>
</xsl:if>

<xsl:if test="normalize-space(department)">
  trims white space characters and tests after this normalization
</xsl:if>

The comparison with the empty string '' is not needed.

Regards,

Joerg

Kazmír, Jaroslav wrote:
TRY THIS:

<xsl:variable name="xtest">
<xsl:value-of select="department"/>
</xsl:variable>

<xsl:choose>
<xsl:when test="string($xtest)!=''">
NON EMPTY
</xsl:when>
<xsl:otherwise>
EMPTY
</xsl:otherwise>
</xsl:choose>

Jaykay

-----Original Message-----
From: Scherler, Thorsten [mailto:[EMAIL PROTECTED]] Sent: Donnerstag, 21. November 2002 14:57
To: Cocoon-Users (E-Mail)
Subject: XSL Element testing whether empty, or not!

Hello group,

newbie question:
How can you test whether a Element contain information or not? I mean
something like the DB command "is not Null" // "is null".

Example:
data.xml
case 1) <department>Elektro</department> case 2) <department />
I want to have the word Department in front of the value as soon as the
<department>is not empty</department>.
I figured out that the string-length(./department/text()) is 19 as soon
<department />. If <department>is not empty</department> is > 19.
So I have written the following xsl (knowing that is a work around but not a
solution).
<xsl:variable name="xtest">
<xsl:value-of select="string-length(./department/text())"/>
</xsl:variable>
<fo:block>
<xsl:choose>
<xsl:when test="$xtest>19">Abteilung: <xsl:value-of
select="./department/text()"/>
</xsl:when>
<xsl:when test="$xtest&lt;20">
<xsl:value-of select="./department/text()"/>
</xsl:when>
</xsl:choose>

Is there a better way to do it?


Mit freundlichem Gruss,

Thorsten Scherler
Marketing / Telefonmarketing

Weidmüller GmbH & Co.
P.O. Box 2807
33058 Paderborn
Tel.:+ 49 - 5252-960-350
Fax:+ 49 - 5252-960-116
eMail: [EMAIL PROTECTED]
http://www.weidmueller.de



---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

To unsubscribe, e-mail:     <[EMAIL PROTECTED]>
For additional commands, e-mail:   <[EMAIL PROTECTED]>

---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

To unsubscribe, e-mail:     <[EMAIL PROTECTED]>
For additional commands, e-mail:   <[EMAIL PROTECTED]>



---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

To unsubscribe, e-mail:     <[EMAIL PROTECTED]>
For additional commands, e-mail:   <[EMAIL PROTECTED]>

Reply via email to