469,578 Members | 1,775 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,578 developers. It's quick & easy.

xsl empty element: how to do?

Hi

I'm having the following problem:

im my xml file there is an element called <gebdatum>22.09.79</gebdatum>
(date of birth in english). this might be full (like in the example) or
empty.
in case it is empty I want to have some text saying that this data is
missing.

I tried like this but it only shows me that text "Keine Daten
vorhanden", but not the data where it exists:
_____________________________________________
<xsl:for-each select="gebdatum">

<xsl:if test="gebdatum=(.!='') ">

<font color="green">Keine Daten vorhanden!</font>

</xsl:if>

<xsl:if test="gebdatum!=(.!='') ">

<xsl:value-of select="gebdatum"/>

</xsl:if>

</xsl:for-each>
_______________________________________

I've also tried with
<choose>
<when>
</when>
<otherwise>
</otherwise>
<choose/>

and it didn't work too

What am I doing wrong?

Any help kindly regarded.

adrian

Aug 24 '05 #1
2 4581
adrian wrote:
Hi

I'm having the following problem:

im my xml file there is an element called <gebdatum>22.09.79</gebdatum>
(date of birth in english). this might be full (like in the example) or
empty.
in case it is empty I want to have some text saying that this data is
missing.

I tried like this but it only shows me that text "Keine Daten
vorhanden", but not the data where it exists:
_____________________________________________
<xsl:template match="gebdatum">
<xsl:choose>
<xsl:when test=".=''">
<span class="nulldatum">Keine Daten vorhanden</span>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
What am I doing wrong?


Trying too hard :-) The simplest route is usually the best. This is the Tao
of XSLT :-)

///Peter
Aug 24 '05 #2
forget about xsl:for-each brrrr..... the best method of that checking is the
string-length() function using. You have to check: xsl:if
test="string-length(element/element/text())!=0". It guarantees performing in
cause of empty element and nonexisting element both.

td
Aug 25 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Derek Basch | last post: by
13 posts views Thread by vega | last post: by
18 posts views Thread by Neal | last post: by
7 posts views Thread by kumar.senthil | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.