Solved

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

Posted on 2004-04-22
4
301 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 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
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, …
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

707 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