My problem:
I have a wealth of atom RSS feed files which have many different atom entries in them and a few overlapping entries between files. I need to find and return an entry based on a URL from any one of the RSS feeds.
Technologies:
This code is being run through PHP 5.2.10's XLSTProcessor extension, which uses XSLT 1, has support for EXSLT and ability to run built in PHP functions. Saxan, Xalan or other similar solutions are not too helpful in this particular situation.
The following code is greatly simplified, but represents my situation.
rss-feed-names.xml:
<feeds>
<feed name="travel.xml"/>
<feed name="holidays.xml"/>
...
<feed name="summer.xml"/>
<feed name="sports.xml"/>
</feeds>
stylesheet.xsl
<xsl:stylesheet ...>
...
<func:function name="cozi:findPost">
<xsl:param name="post-url"/>
<xsl:variable name="blog-feeds" select="document('rss-feed-names.xml')/feeds"/>
<xsl:for-each select="$blog-feeds/feed">
<xsl:variable name="feed-file" select="document(@name)/atom:feed"/>
<xsl:variable name="feed-entry" select="$feed-file/atom:entry[atom:link[contains(@href, $post-url)]]"/>
<xsl:if test="$feed-entry">
<func:result select="$feed-entry"/><!-- this causes errors if more than one result is found -->
</xsl:if>
</xsl:for-each>
</func:function>
</xsl:stylesheet>
...
This code works just fine iff the atom entry that we're looking for appears in ONE of the files we look through. It may appear multiple times within that file, but as soon as it appears in two or more files, the code breaks because func:result was already instantiated and is being over-written, which is a no-no in XSLT.
If there is a way to ACTUALLY exit an EXSLT function or xsl:for-each "loop" (you can assign a return variable for a function, but the function continues; and for-each's are actually not loops, but more similar to function maps), that would be ideal but I have not found a way yet.
I have considered combining all feeds into one variable and removing the for-each loop altogether, but have had problems getting this to work from the beginning.
Any other possible solutions, ideas or pointers are much appreciated! The file relationship here and XML is pretty hard to change, so solutions suggesting such a change are not ideal.
Thanks in advance,
Tristan Eastburn