[XML4Lib] difficulty with following-sibling axis in XSLT
Peter Binkley
peter.binkley at ualberta.ca
Mon May 26 16:32:32 EDT 2008
Something like this would do it:
<xsl:template match="span[@class='title']">
<xsl:variable name="this" select="."/>
<xsl:variable name="infos" select="../span[@class='info'][count($this |
preceding-sibling::span[@class='title'][1]) = 1]"/>
<xsl:value-of select="count($infos)"/>
</xsl:template>
For each title span, the $infos variable selects those info spans for whom
the first preceding title span and the title span of interest ("$this") are
one and the same.
Peter
On 2008/05/26 8:58 AM, "jfitzgibbon at galwaylibrary.ie"
<jfitzgibbon at galwaylibrary.ie> wrote:
> 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
>
>
>
> _______________________________________________
> XML4Lib mailing list
> XML4Lib at webjunction.org
> http://lists.webjunction.org/mailman/listinfo/xml4lib
>
More information about the XML4Lib
mailing list