|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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??? |
|
#2
|
|||
|
|||
|
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 ![]() |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > displaying first and second nodes in an xml document |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|