Solved

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

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

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…
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.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

840 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