XML For Loop Query

Iain

Usenet Archive
Joined
Jul 14, 2000
Messages
69
Reaction score
0
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:eek:utput 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>
 

Richard Tobin

Usenet Archive
Joined
Jan 6, 2000
Messages
4,251
Reaction score
0
Iain said:
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
 

Iain

Usenet Archive
Joined
Jul 14, 2000
Messages
69
Reaction score
0
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
 

Richard Tobin

Usenet Archive
Joined
Jan 6, 2000
Messages
4,251
Reaction score
0
Iain said:
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
 

Patrick TJ McPhee

Usenet Archive
Joined
Apr 2, 2000
Messages
269
Reaction score
0
% 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]">
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,208
Messages
3,104,802
Members
249,594
Latest member
henrywalsh

Latest Threads

Top