[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Print elements by element_order_no tag?

Posted on 2008-06-25
5
Medium Priority
?
241 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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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…
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…
Suggested Courses

656 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