XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 4th, 2004, 05:46 AM
1ei1a 1ei1a is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 32 1ei1a User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 28 m 13 sec
Reputation Power: 5
displaying first and second nodes in an xml document

I am trying to perform a simple action in my xslt document, but it's become frustratingly difficult to get it working satisfactorily.

I want to sort the xml document by date so that the most recent article is first. I then want to display details of the most recent article, details of the second most recent article, and a link to the rest of the articles.

However, it seems I can't use the <xsl:sort select="Date"> statement without putting it in a foreach loop ... obviously not what I want to do as it will mean I end up with 5 iterations through my xslt when I only want to show the last two insideview nodes.

My xml document looks like this:

<InsideViewList>
<InsideView>
<Title>story four</Title>
<StandFirst>standfirst four</StandFirst>
<Date>2004-07-26T00:00:00</Date>
<ImagePath></ImagePath>
<XMLDoc>storyfour</XMLDoc>
</InsideView><InsideView>
<Title>story five</Title>
<StandFirst>standfirst five</StandFirst>
<Date>2004-08-03T00:00:00</Date>
<ImagePath></ImagePath>
<XMLDoc>storyfive</XMLDoc>
</InsideView><InsideView>
<Title>story three</Title>
<StandFirst>standfirst three</StandFirst>
<Date>2004-08-01T00:00:00</Date>
<ImagePath></ImagePath>
<XMLDoc>storythree</XMLDoc>
</InsideView><InsideView>
<Title>story two</Title>
<StandFirst>standfirst two</StandFirst>
<Date>2004-08-03T00:00:00</Date>
<ImagePath></ImagePath>
<XMLDoc>storytwo</XMLDoc>
</InsideView><InsideView>
<Title>story one</Title>
<StandFirst>standfirst one</StandFirst>
<Date>2004-07-30T00:00:00</Date>
<ImagePath></ImagePath>
<XMLDoc>storyone</XMLDoc>
</InsideView>
</InsideViewList>

My xslt look like this:


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="InsideViewList">
<table width="100%" cellpadding="0" border="0" cellspacing="0">
<tr>
<td valign="top" class="headingBar" colspan="3" width="100%" background="/images/heading_slice.jpg" style="padding-left:10px">Inside View</td>
</tr><tr>
<td valign="top" width="75%">
<table width="100%" cellpadding="0" cellspacing="0" border="0" align="left" style="margin-top:7px; padding-right:10px;">
<tr>
<td valign="top" rowspan="3" height="100%" style="padding-right:15px; padding-left:0px;">
<img>
<xsl:attribute name="src"><xsl:value-of select="InsideView/ImagePath[position() = 1]"/></xsl:attribute>
</img>
</td>
<td valign="top" class="headingText" style="padding-bottom:14px;"><xsl:value-of select="InsideView/Title[position() = 1]" /></td>
</tr><tr>
<td valign="top" class="normalText"><xsl:value-of select="InsideView/StandFirst[position() = 1]" /></td>
</tr><tr>
<td valign="top" align="right"><a class="main"><xsl:attribute name="href"><xsl:value-of select="InsideView/XMLDoc[position() = 1]" /></xsl:attribute>Full article »</a></td>
</tr>
</table>
</td>
<td valign="top" background="/images/grey_vert_9c9c9c.gif"><img src="/images/grey_vert_9c9c9c.gif" alt="" /></td>
<td valign="top" width="25%" class="backGroundColor" style="margin-bottom:0px; padding-bottom:0px;">
<table border="0" cellpadding="0" cellspacing="0" height="100%" width="95%" style="margin-top:7px; margin-left:8px;">
<tr>
<td valign="top" class="boldText" height="30px">Last Inside View:<!-- now I want to display details of the second last article --></td>
</tr>
<tr>
<td valign="top" style="padding-left:15px; padding-bottom:4px;" class="normalText">
<ul><li>
<a class="main"><xsl:attribute name="href"><xsl:value-of select="InsideView/XMLDoc[position() = 2]" /></xsl:attribute>
<xsl:value-of select="InsideView/Title[position() = 2]" />
</a></li>
</ul>
</td>
</tr>
<tr>
<td valign="top" align="left"><hr class="hrGrey" width="95%"/></td>
</tr><tr>
<td valign="top" style="padding-left:15px; padding-bottom:12px;">
<ul>
<li><a href="/Archive.aspx#InsideView" class="main">Archive</a></li>
</ul>
</td>
</tr>
</table>
</td>
</tr><tr>
<td valign="top" colspan="3" style="padding-top:0px; margin-top:0px;" background="/images/blue_c6d2ec.gif" height="1px" ><img src="/images/blue_c6d2ec.gif" alt="" valign="bottom" height="1px" width="100%"/></td>
</tr><tr>
<td><img src="/images/1ptrans.gif" alt="" valign="bottom" height="13px" width="100%"/></td>
</tr><tr>
<td valign="top" colspan="3" background="/images/grey_hor_9c9c9c.gif"></td>
</tr>
</table>
</xsl:template>
</xsl:stylesheet>

The errors are occuring on the bold, italic lines. How can I sort the document and get the emphasised lines working??

Any ideas???

Reply With Quote
  #2  
Old August 4th, 2004, 08:55 AM
kid23 kid23 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 62 kid23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
I had similar issues which forced me to work otherwise.. but in your case, you might find clues on this page :

http://www.dpawson.co.uk/xsl/sect2/sect21.html

Look at the bottom, there are two links to "sorting & grouping" and "sorting".. the techniques they explain are often helpful.

Hope this helps

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > displaying first and second nodes in an xml document


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT