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 7832693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T12:21:25+00:00 2026-06-02T12:21:25+00:00

I want to test for events within a group that qualify for both city

  • 0

I want to test for events within a group that qualify for both city and current-date() so that I can output a header.

To find the city ($place eq //event/@city) seems to work. But I can’t figure out how to express “some eventTime/@date is less than $today”. The error message is “A sequence of more than one item is not allowed as the second operand of ‘eq'” Which is confusing because I’ve written test=”($place eq //event/@city) and (xs:date($today) lt xs:date(//eventTime/@date)).

How should I be comparing $today to the @date in my eventTime? Here’s the input.

<calendar>  
<group month="2012-04-01">
    <event city="paris">
        <eventTime date="2012-04-02"/>
        <eventText>Paris - expired April date</eventText>
    </event>
    <event city="london">
        <eventTime date="2012-04-19"/>
        <eventText>London - current April 19 date</eventText>
    </event>
    <event city="london">
        <eventTime date="2012-04-24"/>
        <eventText>London - current April date</eventText>
    </event>
</group>
<group month="2012-05-01">
    <event city="london">
        <eventTime date="2012-05-02"/>
        <eventText>London - current May date</eventText>
    </event>
    <event city="paris">
        <eventTime date="2012-05-01"/>
        <eventText>Paris - current May date</eventText>
    </event>
    <event city="london">
        <eventTime date="2012-05-02"/>
        <eventText>London - current May date</eventText>
    </event>
</group>

</calendar>

Here’s the XSLT:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:xs="http://www.w3.org/2001/XMLSchema"
                xmlns:fn="http://johnadamturnbull.com/xslt"
                exclude-result-prefixes="xs"
                version="2.0" >

    <xsl:output method="html" indent="yes" name="html"/>

    <xsl:param name="place" as="xs:string" required="yes"></xsl:param>
    <xsl:variable name="today" select="current-date()" as="xs:date"/>

      <xsl:template match="/">
        <html>
           <body>
         <xsl:apply-templates select="calendar/group"/>
        </body>
        </html>  
    </xsl:template>



    <xsl:template match = "group">

        <xsl:if test="($place eq //event/@city) and
               (xs:date($today) ge xs:date(//eventTime/@date))">

              <h4 class = "dateHeader">
                    <xsl:value-of select="format-date(./@month,'[MNn] [Y]')"/>
                </h4>
                <ul>
                    <xsl:apply-templates select="event"></xsl:apply-templates>
                </ul>
        </xsl:if>
    </xsl:template>

    <xsl:template match="event">
       <xsl:variable name="eventTime" select="eventTime/@date" as="xs:date"/>
        <xsl:choose>
            <xsl:when test="($eventTime ge $today) and
                            (($place eq @city) or (@city eq ''))">
                <li>
                        <xsl:apply-templates></xsl:apply-templates>
                </li>
            </xsl:when>
            </xsl:choose>
    </xsl:template>

</xsl:stylesheet>
  • 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-06-02T12:21:29+00:00Added an answer on June 2, 2026 at 12:21 pm

    There isn’t an example of what the HTML output is supposed to be, but I’m pretty sure I can tell what you’re trying to achieve.

    I think your XSLT can be simplified by removing the xsl:if and xsl:choose and adding predicates to do your testing.

    This XSLT 2.0 stylesheet:

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
      xmlns:xs="http://www.w3.org/2001/XMLSchema" 
      xmlns:fn="http://johnadamturnbull.com/xslt" exclude-result-prefixes="xs fn" version="2.0">
      <xsl:output method="html" indent="yes" name="html"/>
      <xsl:strip-space elements="*"/>
    
      <xsl:param name="place" as="xs:string" required="yes"/>
      <xsl:variable name="today" select="current-date()" as="xs:date"/>
    
      <xsl:template match="/">
        <html>
          <body>
            <xsl:apply-templates select="calendar/group"/>
          </body>
        </html>
      </xsl:template>
    
      <!--Match group if @city matches $place or is empty and has an eventTime
      with a @date that is greater than or equal to today's date.-->
      <xsl:template match="group[event[@city=$place or @city=''][xs:date(eventTime/@date) >= $today]]">
          <h4 class="dateHeader">
            <xsl:value-of select="format-date(@month,'[MNn] [Y]')"/>
          </h4>
          <ul>
            <!--Only apply-templates to events that have a @city that matches $place
            or has a @city that is empty.-->
            <xsl:apply-templates select="event[@city=$place or @city='']"/>
          </ul>
      </xsl:template>
    
      <!--Only match events that have an eventTime with a @date that is greater than 
      or equal to today's date.-->
      <xsl:template match="event[@city=$place or @city=''][xs:date(eventTime/@date) >= $today]">
        <li>
          <xsl:apply-templates/>
        </li>
      </xsl:template>
    
      <xsl:template match="event"/>
    
    </xsl:stylesheet>
    

    applied to your example XML input produces this HTML output:

    <html>
       <body>
          <h4 class="dateHeader">April 2012</h4>
          <ul>
             <li>London - current April 19 date</li>
             <li>London - current April date</li>
          </ul>
          <h4 class="dateHeader">May 2012</h4>
          <ul>
             <li>London - current May date</li>
             <li>London - current May date</li>
          </ul>
       </body>
    </html>
    

    If this isn’t what you’re looking for, please add an example of what the HTML output should look like.

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

Sidebar

Related Questions

I want to test for a tap event within a Core Text CTLineRef variable.
I want to send various system event from my test application so that i
I have been reading a lot about test-driven development and decided that I want
I have an instrumentation that I want to use to test my application, but
i have a webpage that host events (example: http://www.mysite.com/test/events/5493.html ) that page holds information
Basically I want to assign events to some controls that are created. I want
I'm posting this for those that still use PrototypeJS and want to test custom
I have the following method where I want to test the event.status property only
I want test a FIX gateway for our company and was wondering if anything
I want to test the login() action in my UsersController.php <?php class UsersController extends

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.