Solved

XSL to WML how do I do a count on matches?

Posted on 2004-04-22
4
294 Views
Last Modified: 2008-03-04
so this sheet outputs values included in the xml file.  How do I do a count on matches?  For instance if I have more than one ground delay.  Is there a way to do a count on the matches and display it?  If there are no matches how can I output alternate text?

<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >

  <xsl:output method="xml" indent="yes"
     doctype-public="-//WAPFORUM//DTD WML 1.1//EN" doctype-system="http://www.wapforum.org/DTD/wml_1.1.xml" />

  <xsl:template match="/">
<wml>
<head>
  <meta name="keywords" content="Delays"/>
</head>

<card id="index" title="Airport Status">
  <p align="left">
    <a href="#card0">Ground Delays</a><br/>
    <a href="#card1">Arrival/Departure Delays</a><br/>
  </p>
</card>

<card id="card0" title="Ground Delays">
  <p align="left">
    <xsl:apply-templates select="/AIRPORT_STATUS_INFORMATION/Delay_type/Ground_Stop_List/Delay" />
  </p>
</card>

<card id="card1" title="Arrival/Departure Delays">
  <p align="left">
    <xsl:apply-templates select="/AIRPORT_STATUS_INFORMATION/Delay_type/Arrival_Departure_Delay_List/Delay" />
  </p>
</card>

</wml>
  </xsl:template>


  <xsl:template match="Delay">
    <xsl:text>Airport: </xsl:text><xsl:value-of select="ARPT" /><br/>
    <xsl:text>Reason: </xsl:text><xsl:value-of select="Reason" /><br/>
  </xsl:template>

  <xsl:template match="Ground_Stop_List/Delay">
    <xsl:text>Airport:</xsl:text><xsl:value-of select="ARPT" /><br/>
    <xsl:text>Reason: </xsl:text><xsl:value-of select="Reason" /><br/>
    <xsl:text>End Time: </xsl:text><xsl:value-of select="End_Time" /><br/>
  </xsl:template>

  <xsl:template match="Arrival_Departure_Delay_List/Delay">
    <xsl:text>Airport:</xsl:text><xsl:value-of select="ARPT" /><br/>
    <xsl:text>Reason: </xsl:text><xsl:value-of select="Reason" /><br/>
    <xsl:text>Average Delay: </xsl:text><xsl:value-of select="Arrival_Departure/Avg" /><br/>  
    <xsl:text>Minimum Delay: </xsl:text><xsl:value-of select="Arrival_Departure/Min" /><br/>
    <xsl:text>Maximum Delay: </xsl:text><xsl:value-of select="Arrival_Departure/Max" /><br/>
  </xsl:template>

</xsl:stylesheet>
0
Comment
Question by:mhixon
  • 2
4 Comments
 
LVL 10

Accepted Solution

by:
Yury_Delendik earned 125 total points
ID: 10891656
...
<card id="card0" title="Ground Delays">
  <xsl:variable name="delays-amount" select="count(/AIRPORT_STATUS_INFORMATION/Delay_type/Ground_Stop_List/Delay)" />
  <p align="left">
  <xsl:choose>
    <xsl:when test="$delays-amount = 0">
       <xsl:text>No delays<xsl:text>
    </xsl:when>
    <xsl:otherwise>
       <xsl:value-of select="$delays-amount" /><xsl:text> delay(s)<xsl:text><br />
       
      <xsl:apply-templates select="/AIRPORT_STATUS_INFORMATION/Delay_type/Ground_Stop_List/Delay" />
    </xsl:otherwise>
  <xsl:choose>
  </p>
</card>
...

same for other cards
0
 

Author Comment

by:mhixon
ID: 10891964
This is returning a 500 server error
0
 
LVL 26

Expert Comment

by:rdcpro
ID: 10892954
A few small well-formedness errors involving closing tags.  Yury meant:

<card id="card0" title="Ground Delays">
  <xsl:variable name="delays-amount" select="count(/AIRPORT_STATUS_INFORMATION/Delay_type/Ground_Stop_List/Delay)" />
  <p align="left">
  <xsl:choose>
    <xsl:when test="$delays-amount = 0">
       <xsl:text>No delays</xsl:text>
    </xsl:when>
    <xsl:otherwise>
       <xsl:value-of select="$delays-amount" /><xsl:text> delay(s)</xsl:text><br />
       
      <xsl:apply-templates select="/AIRPORT_STATUS_INFORMATION/Delay_type/Ground_Stop_List/Delay" />
    </xsl:otherwise>
  </xsl:choose>
  </p>
</card>

It wouldn't hurt to check the well-formedness of an XSLT before you upload it to your server, as most of us Experts here simply type in the answers...there's inevitably going to be small typos.  A lot of the time we're just showing you the way, and we don't have time to set up a test case.  ;^)

Regards,
Mike Sharp


0
 

Author Comment

by:mhixon
ID: 10899891
Thanks Mike,

I actually figured this out....sorry about the rush to judgement.  Thanks Yury it works like a charm...exactly what I was looking for.  
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now