Solved

Print elements by element_order_no tag?

Posted on 2008-06-25
5
234 Views
Last Modified: 2013-11-18
Lets say i have this xml structure:

<golfers>
   <golfer element_order_no="2" skill="excellent" handicap="10" clubs="Taylor Made" id="1111">
         <name>
             <firstName>Heedy</firstName>
             <lastName>Wahlin</lastName>
         </name>
         <favoriteCourses>
             <course city="Pinetop" state="AZ" name="Pinetop Lakes CC"/>
             <course city="Phoenix" state="AZ" name="Ocotillo"/>
             <course city="Snowflake" state="AZ" name="Silver Creek"/>
         </favoriteCourses>
      </golfer>
   <golfer element_order_no="1" skill="moderate" handicap="12" clubs="Taylor Made" id="2222">
     <name>
       <firstName>Dan</firstName>
       <lastName>Wahlin</lastName>
       </name>
       <favoriteCourses>
            <course city="Pinetop" state="AZ" name="Pinetop Lakes CC"/>
            <course city="Pinetop" state="AZ" name="White Mountain CC"/>
            <course city="Springville" state="UT" name="Hobble Creek"/>
       </favoriteCourses>
      </golfer>
        <golfer element_order_no="4" skill="moderate" handicap="12" clubs="Taylor Made" id="2222">
     <name>
       <firstName>Dan</firstName>
       <lastName>Wahlin</lastName>
       </name>
       <favoriteCourses>
            <course city="Pinetop" state="AZ" name="Pinetop Lakes CC"/>
            <course city="Pinetop" state="AZ" name="White Mountain CC"/>
            <course city="Springville" state="UT" name="Hobble Creek"/>
       </favoriteCourses>
      </golfer>
        <golfer element_order_no="3" skill="moderate" handicap="12" clubs="Taylor Made" id="2222">
     <name>
       <firstName>Dan</firstName>
       <lastName>Wahlin</lastName>
       </name>
       <favoriteCourses>
            <course city="Pinetop" state="AZ" name="Pinetop Lakes CC"/>
            <course city="Pinetop" state="AZ" name="White Mountain CC"/>
            <course city="Springville" state="UT" name="Hobble Creek"/>
       </favoriteCourses>
      </golfer>
</golfers>

Here is the xslt file:

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes" method="html"/>
<xsl:template match="/">
      <html>
      <head>
            <style type="text/css">
                  .blackText {
                        font-family:arial;
                        color:#000000;
                  }
                  .largeYellowText {
                        font-family:arial;
                        font-size:18pt;
                        color:#ffff00;
                  }
                  .largeBlackText {
                        font-family:arial;
                        font-size:14pt;
                        color:#000000;
                  }
                  .borders {
                        border-left:1px solid #000000;
                        border-right:1px solid #000000;
                        border-top:1px solid #000000;
                        border-bottom:1px solid #000000;
                  }
            </style>
      </head>
      <body bgcolor="#ffffff">
      <span class="largeBlackText">
            <b>Golfers: </b>
      </span>
      <xsl:apply-templates/>
      </body>
      </html>
</xsl:template>
      
<xsl:template match="golfers">
<xsl:apply-templates/></xsl:template>

      <xsl:template match="golfer">
        <table class="borders" border="0" width="640" cellpadding="4" cellspacing="0" bgcolor="#efefef">
            <xsl:apply-templates select="name"/>
            <tr class="blackText">
                  <td width="12%" align="left">
                        <b>Skill: </b>
                  </td>
                  <td width="12%" align="left">
                        <xsl:value-of select="@skill"/>
                  </td>
                  <td width="12%" align="left">
                        <b>Handicap: </b>
                  </td>
                  <td width="12%" align="left">
                        <xsl:value-of select="@handicap"/>
                  </td>
                  <td width="12%" align="left">
                        <b>Clubs: </b>
                  </td>
                  <td width="40%" align="left">
                        <xsl:value-of select="@clubs"/>
                  </td>
            </tr>
            <tr>
                  <td colspan="6">&#xa0;</td>
            </tr>
            <tr class="blackText">
                  <td colspan="6" class="largeBlackText">Favorite Courses</td>
            </tr>
            <tr>
                  <td colspan="2"><b>City: </b></td>
                  <td colspan="2"><b>State: </b></td>
                  <td colspan="2"><b>Course: </b></td>
            </tr>
            <xsl:apply-templates select="favoriteCourses"/>
        </table>
      </xsl:template>
      
<xsl:template match="name">
      <tr>
            <td colspan="6" class="largeYellowText" bgcolor="#02027a">
                  <xsl:value-of select="firstName"/>&#xa0;
                  <xsl:value-of select="lastName"/>
            </td>
      </tr>
</xsl:template>
      
<xsl:template match="favoriteCourses">
      <xsl:apply-templates/></xsl:template>
      
      <xsl:template match="course">
            <tr class="blackText">
                  <td colspan="2" align="left">
                        <xsl:value-of select="@city"/>
                  </td>
                  <td colspan="2" align="left">
                        <xsl:value-of select="@state"/>
                  </td>
                  <td colspan="2" align="left">
                        <xsl:value-of select="@name"/>
                  </td>
            </tr>
      </xsl:template>
      
</xsl:stylesheet>

How to i show the elements ascending or descending by the element_order_no tag???

Thank you.
0
Comment
Question by:drcyrus3d
[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
  • 3
  • 2
5 Comments
 
LVL 82

Accepted Solution

by:
hielo earned 500 total points
ID: 21869242
Instead of:
<xsl:template match="golfers">
<xsl:apply-templates/></xsl:template>


use:
<xsl:template match="golfers">
 <xsl:apply-templates>
  <xsl:sort select="@element_order_no"/>
 </xsl:apply-templates>
</xsl:template>
0
 
LVL 1

Author Closing Comment

by:drcyrus3d
ID: 31470719
Thank you!
0
 
LVL 1

Author Comment

by:drcyrus3d
ID: 21869319
is there a way i can choose between asc or desc? Cause right now is in asc mode. :)

Thanks.
0
 
LVL 82

Expert Comment

by:hielo
ID: 21869340
The syntax is:
<xsl:sort
select="expression"
lang="language-code"
data-type="text|number|qname"
order="ascending|descending"
case-order="upper-first|lower-first"/>

so use:
<xsl:template match="golfers">
 <xsl:apply-templates>
  <xsl:sort select="@element_order_no" order="descending"/>
 </xsl:apply-templates>
</xsl:template>
0
 
LVL 1

Author Comment

by:drcyrus3d
ID: 21869396
Thank you!
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

729 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