[XML4Lib] difficulty with following-sibling axis in XSLT

Charles Yates ceyates at stanford.edu
Mon May 26 12:17:26 EDT 2008


you want to do 'grouping'

if you are using a xslt 2.0 processor, you have grouping built in:
http://www.w3.org/TR/xslt20/#grouping
http://www.xml.com/pub/a/2003/11/05/tr.html

otherwise check this out:
http://jenitennison.com/xslt/grouping/index.html#by-content


On May 26, 2008, at 8:58 AM, <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