[XML4Lib] difficulty with following-sibling axis in XSLT
jfitzgibbon at galwaylibrary.ie
jfitzgibbon at galwaylibrary.ie
Mon May 26 11:58:02 EDT 2008
Hi,
I have an XML file which I saved from a HTML file and it has the following
structure.
<library>
<span class="title">Wuthering Heights</span>
<span class="info">paperback</span>
<span class="info">unavailable</span>
<span class="title">Tom Sawyer</span>
<span class="info">Audio Book</span>
<span class="info">Available</span>
<span class="info">Unabridged</span>
</library>
The problem is that all span tags with an attribute of info are siblings
of each other and I have no way of knowing how many span tags with a class
of info occur after each title. For example, if I try to access all the
information about 'Wuthering Heights' and only 'Wuthering Heights' I am
running into problems.
For example, if I try
<xsl:template match="library/span[@class='title' and .='Wuthering
Heights']">
<xsl:for-each select="following-sibling::span[@class='info']">
<p>
<xsl:value-of select="."/>
</p>
</xsl:for-each>
</xsl:template>
I will retrieve all information on all books and not just the information
on "Wuthering Heights".
I get
<p>paperback</p>
<p>unavailable</p>
<p>Audio Book</p>
<p>Available</p>
<p>Unabridged</p>
How do I limit my results to those span elements containing information on
"Wuthering Heights"?
This is a problem which I encounter frequently when I convert a HTML
document to XML.
I would appreciate any advice.
Regards
John
More information about the XML4Lib
mailing list