XSL testing empty strings with <xsl:if> and sorting

Posted by AdRock on Stack Overflow See other posts from Stack Overflow or by AdRock
Published on 2010-04-24T18:22:31Z Indexed on 2010/04/24 18:33 UTC
Read the original article Hit count: 882

Filed under:

I am having trouble with a template that has to check 3 different nodes and if they are not empty, print the data

I am using for each node then doing the output but it is not printing anything. It is like the test returns zero.

I have selected the parent node of each node i want to check the length on as the template match but it still doesn't work.

Another thing, how do i sort the list using . I tried using this but i get an error about loading the stylesheet. If i take out the sort it works

<xsl:template match="folktask/member">
    <xsl:if test="user/account/userlevel='3'">
        <xsl:sort select="festival/event/datefrom"/>
        <div class="userdiv">   
            <xsl:apply-templates select="user"/>    
            <xsl:apply-templates select="festival"/>    
<xsl:template match="festival">
    <xsl:apply-templates select="contact"/>

This should hopefully finish all my stylesheets.

This is the template I am calling

<xsl:template match="contact">
 <xsl:if test="string-length(contelephone)!=0">
  <div class="small bold">TELEPHONE:</div>
  <div class="large">
   <xsl:value-of select="contelephone/." />

 <xsl:if test="string-length(conmobile)!=0">
  <div class="small bold">MOBILE:</div>
  <div class="large">
   <xsl:value-of select="conmobile/." />

 <xsl:if test="string-length(fax)!=0">
  <div class="small bold">FAX:</div>
  <div class="large">
   <xsl:value-of select="fax/." />

and a section of my xml. If you need me to edit my post so you can see the full code i will but the rest works fine.

  <user id="4">
    <name>Connor Lawson</name>
    <address1>12 Ash Way</address1>
    <postcode>SN3  6GS</postcode>
    <email>[email protected]</email>
  <festival id="1">
    <eventname>Oxford Folk Festival</eventname>
    <eventpostcode>OX1 9BE</eventpostcode>
    <conname>Stuart Vincent</conname>
    <conaddress1>P.O. Box 642</conaddress1>
    <conpostcode>OX1 3BY</conpostcode>
    <contelephone>01865 79073</contelephone>
    <conemail>[email protected]</conemail>

© Stack Overflow or respective owner

Related posts about xsl

Related posts about Xml