Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > xsl empty element: how to do?

Reply
Thread Tools

xsl empty element: how to do?

 
 
adrian
Guest
Posts: n/a
 
      08-24-2005
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

 
Reply With Quote
 
 
 
 
Peter Flynn
Guest
Posts: n/a
 
      08-24-2005
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>
<xsltherwise>
<xsl:value-of select="."/>
</xsltherwise>
</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
 
Reply With Quote
 
 
 
 
toudidel
Guest
Posts: n/a
 
      08-25-2005
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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Altova Mapforce - xml 2 xml map: empty elements output although input element is not empty Lukas XML 3 11-10-2005 02:25 PM
XSL Question tp xsl:for-each and xsl:variable schaf@2wire.ch XML 1 05-27-2005 09:25 PM
empty lists vs empty generators Brian Roberts Python 12 05-04-2005 08:59 PM
Check if a directory is empty and empty it Marcia Hon C Programming 8 02-14-2004 03:53 AM
empty/non-empty element John XML 1 07-16-2003 10:23 AM



Advertisments