Solved

Print elements by element_order_no tag?

Posted on 2008-06-25
5
220 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
two submit buttons one form 15 75
CSS HELP 6 84
XML Data Missing in PHP SimpleXML 8 45
Questions about this React unit test 4 46
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…
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…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

867 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

21 Experts available now in Live!

Get 1:1 Help Now