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:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old July 24th, 2002, 05:21 PM
jough jough is offline
El Guapo
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2001
Location: You have moved into a dark place. It is pitch black. You are likely to be eaten by a grue.
Posts: 56 jough User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 7 m 47 sec
Reputation Power: 7
XSLT - Sorting, Limiting Nodes

Hi,

I have a long XML document that I'm using to write and sort news for my personal website that I transform with XSLT and pre-process with PHP/Sablotron to produce valid XHTML.

But I don't want to display *every* node in the tree - only the first five full entries, and then just the headlines for the rest.

Is there a way to use XSL to transform this page thusly? Then of course I'd need to have visitors click on the headlines to traverse to just *that* node (also pre-processed with PHP/Sablot) on a results page.

My XML document is here:
http://64.191.4.184/home.xml

and the XSL transformation that I'm using for it is here:

http://64.191.4.184/home.xsl

And if you simply go to:

http://64.191.4.184/index.php

you can see them processed with Sablot, CSS, etc.

-- Jough
__________________
See my PHP in action:
Poetry Archives

Reply With Quote
  #2  
Old July 26th, 2002, 03:56 PM
justin_dago justin_dago is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: new york
Posts: 84 justin_dago User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
XPATH will help you accomplish this..

here's an introduction:
http://www.devshed.com/Server_Side/XML/XPath/page1.html


you're links are not loading for me right now, so this is all i can say at the moment, but this should get you started

Reply With Quote
  #3  
Old July 28th, 2002, 01:53 AM
jough jough is offline
El Guapo
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2001
Location: You have moved into a dark place. It is pitch black. You are likely to be eaten by a grue.
Posts: 56 jough User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 7 m 47 sec
Reputation Power: 7
Thanks for your reply. I had read that article, but it doesn't really go in depth enough for my needs (like many articles on that site - great introductions if you've never heard of a technology, but they generally don't give you enough info to be useful for a real-world application).

Anyway, traversing the nodes isn't really a problem - I just can't seem to find a way to limit node retreival in XSLT (using XPath or otherwise) as I would in say, a SQL db call:

SELECT field FROM table WHERE var='value' LIMIT 0,5;

Is there way to limit node traversal in XSL/XPath/XLink/XPointer/XWhatever?

-- Jough

Reply With Quote
  #4  
Old July 28th, 2002, 06:19 PM
justin_dago justin_dago is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: new york
Posts: 84 justin_dago User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
i'm not an expert, but
how about something like this:


<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">


<xsl:for-each select="//adjust-your-position">

<xsl:if test="position() < 6">
<xsl:value-of select="@value"/>
</xsl:if>

</xsl:for-each>
</xsl:template>
</xsl:stylesheet>


Reply With Quote
  #5  
Old July 31st, 2002, 05:30 PM
jough jough is offline
El Guapo
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2001
Location: You have moved into a dark place. It is pitch black. You are likely to be eaten by a grue.
Posts: 56 jough User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 7 m 47 sec
Reputation Power: 7
Well, I was doing something similar, Jason:

Code:
<xsl:choose>
        <xsl:when test="position() <=5">
          <xsl:apply-templates select="headline" />
          <xsl:apply-templates select="date" />
          <xsl:apply-templates select="body" /> 
        </xsl:when>
        <xsl:otherwise>
          <xsl:apply-templates select="headline" />
        </xsl:otherwise>
     </xsl:choose>


But there's a bug in Sablotron that parses child nodes of the root element incorrectly - it parses whitespace text as a child node, regardless of whether there's an <xml:strip-space elements="*" /> transormation or not.

So the above works with the MS XML 4 parser but not with Sablotron. I've e-mailed them to see if they have a fix or workaround. I'll post it here when I get a reply.

-- Jough

P.S. And yes, I suppose I could just double my position() test number to account for the whitespace text nodes, but that would be wrong, especially if I want to code for standards compliance across multiple platforms - it's much better to get the Ginger Alliance people (those wacky Czechs who make Sablotron) to get their parser up to spec.

Reply With Quote
  #6  
Old August 6th, 2002, 10:34 AM
justin_dago justin_dago is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: new york
Posts: 84 justin_dago User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
ahhhhh,

good to know thanks for the heads-up.

let me know ..

sorry, i couldn't help you out!!


================
justin_dago

Reply With Quote
  #7  
Old August 6th, 2002, 11:16 AM
jough jough is offline
El Guapo
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2001
Location: You have moved into a dark place. It is pitch black. You are likely to be eaten by a grue.
Posts: 56 jough User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 7 m 47 sec
Reputation Power: 7
That's okay. Actually, I wound up doing it a slightly different way, which selects the child nodes of the root more exactly:

Code:
  <xsl:template match="entry[position() <=5]">
        Do Something
  </xsl:template>
  
  <xsl:template match="entry[position() >=6]">
        Do Something Else
  </xsl:template>


That way, I specifically only select the "entry" elements whose positions are tested in the brackets. Sablotron wrongly implements the parsing of white space (they say that's how it *should* be done, but the W3C spec, as well as every other parser on the market that I've tested, seems to disagree with them) but either way, you can always test using element[child/test/condition].

Good to know.

Cheers,

-- Jough

Reply With Quote
  #8  
Old August 6th, 2002, 06:22 PM
justin_dago justin_dago is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: new york
Posts: 84 justin_dago User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Cool, Thanks jough!!

Have fun!




justin.dago

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > XSLT - Sorting, Limiting Nodes


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


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





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway