xsl empty element: how to do?

Discussion in 'XML' started by adrian, Aug 24, 2005.

  1. adrian

    adrian Guest

    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
     
    adrian, Aug 24, 2005
    #1
    1. Advertising

  2. adrian

    Peter Flynn Guest

    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:eek:therwise>
    <xsl:value-of select="."/>
    </xsl:eek:therwise>
    </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
     
    Peter Flynn, Aug 24, 2005
    #2
    1. Advertising

  3. adrian

    toudidel Guest

    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
     
    toudidel, Aug 25, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt
    Replies:
    0
    Views:
    383
  2. John

    empty/non-empty element

    John, Jul 15, 2003, in forum: XML
    Replies:
    1
    Views:
    1,045
    Klaus Johannes Rusch
    Jul 16, 2003
  3. Matt
    Replies:
    6
    Views:
    4,075
  4. Replies:
    1
    Views:
    3,636
    A. Bolmarcich
    May 27, 2005
  5. Lukas
    Replies:
    3
    Views:
    834
    spiff
    Nov 10, 2005
Loading...

Share This Page