Solved

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

Posted on 2004-04-22
4
287 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
Comment Utility
...
<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
Comment Utility
This is returning a 500 server error
0
 
LVL 26

Expert Comment

by:rdcpro
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
PHP Curl Multi-exec 13 60
Custom Ribbon doesn't refresh 7 59
Strange html entity encoding by tidy 14 68
C# SQL BULK INSERT CLASS 5 33
The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

762 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

6 Experts available now in Live!

Get 1:1 Help Now