Solved

Print elements by element_order_no tag?

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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Create XML 5 52
xpath sql query 2008 8 63
JQuery to parse xml string and get element by id 4 64
Powershell script to zip up xml files in a directory 13 34
Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

733 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