Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 776101
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T19:23:56+00:00 2026-05-14T19:23:56+00:00

I am having trouble with a template that has to check 3 different nodes

  • 0

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 <xsl:if test="string-length(node) != 0"> 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 <datefrom>. I tried using this but I get an error about loading the stylesheet. If I take out the sort it works

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

    <xsl:template name="hoo" match="/">
        <html>
            <head>
                <title>Registered Festival Organisers and Festivals</title>
                <link rel="stylesheet" type="text/css" href="userfestival.css" />
            </head>
            <body>
                <h1>Registered Festival Organisers and Festivals</h1>
                <h3>Ordered by the festival date ascending</h3>                 
                <xsl:apply-templates select="folktask/member"/>

                <xsl:if test="position()=last()">
                    <div class="count"><h2>Total number of festival organisers: <xsl:value-of select="count(/folktask/member/user/account/userlevel[text()=3])"/></h2></div>
                    <div class="count"><h2>Total number of festivals: <xsl:value-of select="count(/folktask/member/festival)"/></h2></div>
                </xsl:if>               
            </body>
        </html>
    </xsl:template>

<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"/>    
        </div>
    </xsl:if>
</xsl:template>

    <xsl:template match="user">
        <xsl:apply-templates select="@id" mode="userid"/>
        <xsl:apply-templates select="personal/name"/>
        <xsl:apply-templates select="personal/address1"/>
        <xsl:apply-templates select="personal/city"/>
        <xsl:apply-templates select="personal/county"/>
        <xsl:apply-templates select="personal/postcode"/>
        <xsl:apply-templates select="personal/telephone"/>
        <xsl:apply-templates select="personal/mobile"/>
        <xsl:apply-templates select="personal/email"/>
        <xsl:apply-templates select="personal"/>
        <xsl:apply-templates select="account/username"/>
        <xsl:apply-templates select="account"/>
    </xsl:template>

    <xsl:template match="festival">
        <xsl:apply-templates select="@id" mode="festid"/>
        <xsl:apply-templates select="event/eventname"/>
        <xsl:apply-templates select="event/url"/>
        <xsl:apply-templates select="event/datefrom"/>
        <xsl:apply-templates select="event/dateto"/>
        <xsl:apply-templates select="event/location"/>
        <xsl:apply-templates select="event/eventpostcode"/>
        <xsl:apply-templates select="event/coords/lat"/>
        <xsl:apply-templates select="event/coords/lng"/>
        <xsl:apply-templates select="contact/conname"/>
        <xsl:apply-templates select="contact/conaddress1"/>
        <xsl:apply-templates select="contact/conaddress2"/>
        <xsl:apply-templates select="contact/concity"/>
        <xsl:apply-templates select="contact/concounty"/>
        <xsl:apply-templates select="contact/conpostcode"/>
        <xsl:apply-templates select="contact"/>
        <xsl:apply-templates select="contact/conemail"/>
    </xsl:template>

    <xsl:template match="@id" mode="userid">
        <div class="heading bold"><h2>USER ID: <xsl:value-of select="." /></h2></div>
    </xsl:template>

    <xsl:template match="personal/name">
        <div class="small bold">NAME:</div>
        <div class="large"><xsl:value-of select="." /></div>
    </xsl:template>

    <xsl:template match="personal/address1">
        <div class="small bold">ADDRESS:</div>
        <div class="large"><xsl:value-of select="." /></div>
    </xsl:template>

    <xsl:template match="personal/city">
        <div class="small bold">CITY:</div>
        <div class="large"><xsl:value-of select="." /></div>
    </xsl:template>

    <xsl:template match="personal/county">
        <div class="small bold">COUNTY:</div>
        <div class="large"><xsl:value-of select="." /></div>
    </xsl:template>

    <xsl:template match="personal/postcode">
        <div class="small bold">POSTCODE:</div>
        <div class="large"><xsl:value-of select="." /></div>
    </xsl:template>

    <xsl:template match="personal/telephone">
        <div class="small bold">TELEPHONE:</div>
        <div class="large"><xsl:value-of select="." /></div>
    </xsl:template>

    <xsl:template match="personal/mobile">
        <div class="small bold">MOBILE:</div>
        <div class="large"><xsl:value-of select="." />
        </div>
    </xsl:template>

    <xsl:template match="personal/email">
        <div class="small bold">EMAIL:</div>
        <div class="large">
            <xsl:element name="a">
                <xsl:attribute name="href">
                    <xsl:text>mailto:</xsl:text>
                    <xsl:value-of select="." />
                </xsl:attribute>
                <xsl:value-of select="." />
            </xsl:element>
        </div>
    </xsl:template>

    <xsl:template match="personal">
        <div class="small bold">SEX:</div>
        <div class="colored bold">
            <xsl:choose>
                <xsl:when test="sex='Male'">
                    <div class="sex male"><xsl:value-of select="sex/."/></div>
                </xsl:when>
                <xsl:otherwise>
                    <div class="sex female"><xsl:value-of select="sex/."/></div>
                </xsl:otherwise>
            </xsl:choose>
        </div>
    </xsl:template>

    <xsl:template match="account/username">
        <div class="small bold">USERNAME:</div>
        <div class="large"><xsl:value-of select="." /></div>
    </xsl:template>


    <xsl:template match="account">
        <div class="small bold">ACCOUNT TYPE:</div>
        <div class="colored ">
            <xsl:choose>
                <xsl:when test="userlevel='1'">
                    <div class="nml bold">Normal User</div>
                </xsl:when>

                <xsl:when test="userlevel='2'">
                    <div class="vol bold">Volunteer</div>
                </xsl:when>

                <xsl:when test="userlevel='3'">
                    <div class="org bold">Organiser</div>
                </xsl:when>

                <xsl:otherwise>
                    <div class="name adm bold">Administrator</div>
                </xsl:otherwise>
            </xsl:choose>
        </div>
    </xsl:template>

    <xsl:template match="@id" mode="festid">
        <div class="heading2 bold"><h2>FESTIVAL ID: <xsl:value-of select="." /></h2></div>
    </xsl:template>

    <xsl:template match="eventname">
        <div class="small bold">EVENT NAME:</div> 
        <div class="large bold"><xsl:value-of select="." /></div>
    </xsl:template>

    <xsl:template match="url">
        <div class="small bold">URL:</div>
        <div class="large">
            <xsl:element name="a">
                <xsl:attribute name="href">
                    <xsl:value-of select="." />
                </xsl:attribute>
                <xsl:value-of select="." />
            </xsl:element>
        </div>
    </xsl:template>

    <xsl:template match="datefrom">
        <div class="small bold">DATE FROM:</div>
        <div class="large"><xsl:value-of select="." /></div>
    </xsl:template>

    <xsl:template match="dateto">
        <div class="small bold">DATE TO:</div>
        <div class="large"><xsl:value-of select="." /></div>
    </xsl:template>

    <xsl:template match="location">
        <div class="small bold">LOCATION:</div>
        <div class="large"><xsl:value-of select="." /></div>
    </xsl:template>

    <xsl:template match="eventpostcode">
        <div class="small bold">POSTCODE:</div>
        <div class="large"><xsl:value-of select="." /></div>
    </xsl:template>

    <xsl:template match="coords/lat">
        <div class="small bold">LATITUDE:</div>
        <div class="large"><xsl:value-of select="." />
        </div>
    </xsl:template>

    <xsl:template match="coords/lng">
        <div class="small bold">LONGITUDE:</div>
        <div class="large"><xsl:value-of select="." />
        </div>
    </xsl:template>

    <xsl:template match="conname">
        <div class="small bold">NAME:</div> 
        <div class="large"><xsl:value-of select="." /></div>
    </xsl:template>

    <xsl:template match="conaddress1">
        <div class="small bold">ADDRESS:</div> 
        <div class="large"><xsl:value-of select="." /></div>
    </xsl:template>

    <xsl:template match="conaddress2">
        <xsl:if test="string-length(conaddress2)!=0">
            <div class="small bold"><xsl:text>&#160;</xsl:text></div>
            <div class="large">
                <xsl:value-of select="." />
            </div>
        </xsl:if>
    </xsl:template>

    <xsl:template match="concity">
        <div class="small bold">CITY:</div>
        <div class="large"><xsl:value-of select="." /></div>
    </xsl:template>

    <xsl:template match="concounty">
        <div class="small bold">COUNTY:</div>
        <div class="large"><xsl:value-of select="." /></div>
    </xsl:template>

    <xsl:template match="conpostcode">
        <div class="small bold">POSTCODE:</div>
        <div class="large"><xsl:value-of select="." /></div>
    </xsl:template>

<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/." />
        </div>
    </xsl:if>

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

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

    <xsl:template match="conemail">
        <div class="small bold">EMAIL:</div>
        <div class="large">
            <xsl:element name="a">
                <xsl:attribute name="href">
                    <xsl:text>mailto:</xsl:text>
                    <xsl:value-of select="." />
                </xsl:attribute>
                <xsl:value-of select="." />
            </xsl:element>
        </div>
    </xsl:template>

</xsl:stylesheet> 

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.

<folktask>
 <member>
  <user id="4">
   <personal>
    <name>Connor Lawson</name>
    <sex>Male</sex>
    <address1>12 Ash Way</address1>
    <address2></address2>
    <city>Swindon</city>
    <county>Wiltshire</county>
    <postcode>SN3  6GS</postcode>
    <telephone>01791928119</telephone>
    <mobile>07338695664</mobile>
    <email>itunestinker@fsmail.co.uk</email>
   </personal>
   <account>
    <username>iTuneStinker</username>
    <password>3a1f5fda21a07bfff20c41272bae7192</password>
    <userlevel>3</userlevel>
    <signupdate>2010-03-26T09:23:50</signupdate>
   </account>
  </user>
  <festival id="1">
   <event>
    <eventname>Oxford Folk Festival</eventname>
    <url>http://www.oxfordfolkfestival.com/</url>
    <datefrom>2010-04-07</datefrom>
    <dateto>2010-04-09</dateto>
    <location>Oxford</location>
    <eventpostcode>OX1 9BE</eventpostcode>
    <coords>
     <lat>51.735640</lat>
     <lng>-1.276136</lng>
    </coords>
   </event>
   <contact>
    <conname>Stuart Vincent</conname>
    <conaddress1>P.O. Box 642</conaddress1>
    <conaddress2></conaddress2>
    <concity>Oxford</concity>
    <concounty>Bedfordshire</concounty>
    <conpostcode>OX1 3BY</conpostcode>
    <contelephone>01865 79073</contelephone>
    <conmobile></conmobile>
    <fax></fax>
    <conemail>stewards@oxfordfolkfestival.com</conemail>
   </contact>
  </festival>
 </member>
</folktask>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T19:23:59+00:00Added an answer on May 14, 2026 at 7:23 pm

    You can sort the elements when you apply a template:

    <xsl:apply-templates select="folktask/member">
      <xsl:sort select="festival/event/datefrom"/>
    </xsl:apply-templates>
    

    You’re also confusing your node context slightly:

    <xsl:template match="conaddress2">
      <xsl:if test="string-length(conaddress2)!=0">
        ...
      </xsl:if>
    </xsl:template>
    

    Should probably be:

    <xsl:template match="conaddress2">
      <xsl:if test="string-length(.)!=0">
        ...
      </xsl:if>
    </xsl:template>
    

    Since you’re matching conaddress2 the context node is set to conaddress2. If you try and use string-length(conaddress2) from this context it means you’re trying to find a conaddress2 child node of the current context node (which is conaddress2). In other words you’re trying to find the length of conaddress2\conaddress2.

    Similarly in this template:

    <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/." />
        </div>
      </xsl:if>
    
      <xsl:if test="string-length(conmobile)!=0">
        <div class="small bold">MOBILE:</div>
        <div class="large">
          <xsl:value-of select="conmobile/." />
        </div>
      </xsl:if>
    
      <xsl:if test="string-length(fax)!=0">
        <div class="small bold">FAX:</div>
        <div class="large">
          <xsl:value-of select="fax/." />
        </div>
      </xsl:if>
    </xsl:template>
    

    You can remove the “/.” from your select expressions. So instead of:

    <xsl:value-of select="contelephone/." />
    

    You can use

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

    (Although both worked the same in my XSLT parser.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Our project has a site template that manages custom properties using SPWeb.Properties. However I
Im having trouble using a .NET COM in vb6, It compiles ok and I
I having trouble in dividing the HTML frames. I have been using the following
I'm having trouble reading a chunked response when using a StreamReader to read the
I am having trouble integrating two products, one of which is mine and they
Having trouble linking the Stomp.framework into an iPhone SDK application. http://code.google.com/p/stompframework/ I follow the
I am having trouble with IE7. I have a header, which is an IMG.
I'm having trouble getting a rotary encoder to work properly with AVR micro controllers.
I've been having trouble getting my ASP.NET application to automatically log users into the
I'm having trouble with global variables in php. I have a $screen var set

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.