XML For Loop Query

I

Iain

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>
 
R

Richard Tobin

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
 
I

Iain

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
 
R

Richard Tobin

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
 
P

Patrick TJ McPhee

% 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

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top