473,385 Members | 1,338 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

XML For Loop Query

Hello. I'm new to the XML lark, I've got a script to display some RSS feeds
on my ASP pages, but I can't work out how to just display the first three...

My XSL stylesheet looks like this... can anyone give me a tip as to how to
stop the for loop after 3 records?

TIA. :)

<?xml version="1.0" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="*">

<xsl:for-each select="//*[local-name()='item']">
<a>
<xsl:attribute name="href">
<xsl:value-of select="*[local-name()='link']"/>
</xsl:attribute>
<xsl:attribute name="target">
<xsl:text>top</xsl:text>
</xsl:attribute>
<xsl:value-of select="*[local-name()='title']"/>
</a><br/>
<xsl:value-of select="*[local-name()='description']"
disable-output-escaping="yes"/>
<br /><br/>
</xsl:for-each>

</xsl:template>
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
</xsl:stylesheet>
Jul 20 '05 #1
4 5653
In article <A8********************@eclipse.net.uk>,
Iain <ia****@lycos.co.you-kay> wrote:
Hello. I'm new to the XML lark, I've got a script to display some RSS feeds
on my ASP pages, but I can't work out how to just display the first three...

My XSL stylesheet looks like this... can anyone give me a tip as to how to
stop the for loop after 3 records? <xsl:for-each select="//*[local-name()='item']">


<xsl:for-each select="(//*[local-name()='item'])[position() <= 3]">

-- Richard

Jul 20 '05 #2


"Richard Tobin" <ri*****@cogsci.ed.ac.uk> wrote in message
news:<cj**********@pc-news.cogsci.ed.ac.uk>...
In article <A8********************@eclipse.net.uk>, Iain <ia****@lycos.co.you-kay> wrote:
Hello. I'm new to the XML lark, I've got a script to display some RSS feeds
on my ASP pages, but I can't work out how to just display the first three...
My XSL stylesheet looks like this... can anyone give me a tip as to how to
stop the for loop after 3 records? <xsl:for-each select="//*[local-name()='item']">

<xsl:for-each select="(//*[local-name()='item'])[position() <= 3]"> -- Richard


Apologies if I emailed you twice with this, hit the wrong button...

That gives me:

The stylesheet does not contain a document element. The stylesheet may be
empty, or it may not be a well-formed XML document.

ASP function calling it looks like this, although it works fine when writing
out every record in the feed:

Function getXML(sourceFile)

dim styleFile

dim source, style

styleFile = Server.MapPath("style/news.xsl")

Dim xmlhttp

Set xmlhttp = Server.CreateObject("Microsoft.XMLHTTP")

xmlhttp.Open "GET", sourceFile, false

xmlhttp.Send

set source = Server.CreateObject("Microsoft.XMLDOM")

source.async = false

source.loadxml(xmlhttp.ResponseText)

set style = Server.CreateObject("Microsoft.XMLDOM")

style.async = false

style.load(styleFile)

getXML = source.transformNode(style)

set source = nothing

set style = nothing

End Function
Jul 20 '05 #3
In article <19********************@eclipse.net.uk>,
Iain <ia****@lycos.co.you-kay> wrote:
That gives me:

The stylesheet does not contain a document element. The stylesheet may be
empty, or it may not be a well-formed XML document.


(Not the greatest error message!)

Sorry, forgot to escape the less-than:
<xsl:for-each select="(//*[local-name()='item'])[position() <= 3]">


should be

<xsl:for-each select="(//*[local-name()='item'])[position() &lt;= 3]">

-- Richard
Jul 20 '05 #4
In article <cj**********@pc-news.cogsci.ed.ac.uk>,
Richard Tobin <ri*****@cogsci.ed.ac.uk> wrote:

% should be
%
% <xsl:for-each select="(//*[local-name()='item'])[position() &lt;= 3]">

I always try to use > in xpath expressions to avoid this issue.

<xsl:for-each select="(//*[local-name()='item'])[3 >= position()]">
--

Patrick TJ McPhee
East York Canada
pt**@interlog.com
Jul 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: jason | last post by:
Access 2000: I have a customer-inventory table I need to loop through and compile a list of all the inventory items the customer is tracking. The problem I am finding is that a simple loop...
3
by: r rk | last post by:
I am trying to write a utility/query to get a report from a table. Below is the some values in the table: table name: dba_daily_resource_usage_v1...
5
by: Eric Culus | last post by:
I seem to be having troubles with this page.... It's an automated mailing script... Steps: - system checks on x dates the variables linked to a maintenance contract (query on db) - when...
14
by: Crimsonwingz | last post by:
Need to calculate a sum based on a number of factors over a period of years. I can use formula ^x for some of it, but need totals to carry over in the sum and have only been able to do this thus...
0
by: Mark Harrison | last post by:
HOWTO: Integrating Posgresql queries into an event loop. Mark Harrison mh@pixar.com May 27, 2004 Problem ------- The commonly used postgresql APIs will block until completed.
14
by: dawnerd | last post by:
Hi, I am developing a CMS and came across something which has never happened to me before, and I re-wrote the specific script twice, both differently, and still had the same error. I'm not sure...
1
by: Manners | last post by:
Hi! I am a VBA newbie, and cant seem to proceed past my current problem. I have a large query, where I need to output a select query based on the parameter set by the do loop. The do loop is...
8
by: SaltyBoat | last post by:
Needing to import and parse data from a large PDF file into an Access 2002 table: I start by converted the PDF file to a html file. Then I read this html text file, line by line, into a table...
2
by: recordlovelife | last post by:
So I am trying to display a title, date, and content of a wordpress blog. Word press provides nice drop in functions to get the job done with simple names like "the_title", and the "the_content" But...
60
by: bonneylake | last post by:
Hey Everyone, What i am trying to do is show previously entered information. I know i need a loop for this , but i am not sure how to loop through this based on my form appears all in the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.