?
Solved

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

Posted on 2004-04-22
4
Medium Priority
?
303 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 10

Accepted Solution

by:
Yury_Delendik earned 500 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
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.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

765 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