xsl-list
[Top] [All Lists]

selecting elements from a flat file

2004-07-15 07:59:03
Hi, 

I am having problems selecting a group of sibling elements from a flat
file.
The file is of the form...

<main>
        <a name='Title'></a>
        <a></a>
        <a></a>
        <a></a>
        <b></b> 
        <a></a> 
        <a></a>
        <b></b> 
        <a></a> 
</main>

and I need to select all the <a> elements between <a name='Title'> and
the first <b> element.

I am trying to use keys to achieve this using the following XSL.....



<xsl:key name="about_st" match="a"
use="generate-id(preceding-sibling::a[(_at_)name='Title'][1])"/>

<xsl:key name="about_en" match="a"
use="generate-id(following-sibling::b[1])"/>
        
<xsl:template match="main">
<manual>
<about>
        <xsl:apply-templates select="a[(_at_)name='Title']"/>
</about>
</manual>
</xsl:template>

<xsl:template match="a[(_at_)name='Title']">
        <xsl:variable name="genID" select="generate-id()"/>
        <xsl:for-each select="key('about_st', $genID)">
                <xsl:apply-templates select="key('about_en', $genID)"/>
        </xsl:for-each>
</xsl:template>

<xsl:template match="a">
        <xsl:value-of select="."/>
</xsl:template> 



The problem is that the first key selects all the <a> elements following
a name='Title'>
but the second key returns nothing.

Can someone point out where I have gone wrong? Or is there a better way
to do this?
(I am trying to do this without using XSL 2 to avoid having to install
additional software
on the customers machine.)

Many thanks,

==========================================

Adrian Jordin
Senior Analyst Developer
ePublishing Department,
Piper Group plc,

Email : ajordin(_at_)piper-group(_dot_)com+

300 Aztec West
Almondsbury
Bristol 
BS32 4SE

Phone + 44 (0) 1454 284900
Fax + 44(0) 1454 284950

Information contained in this e-mail is intended for the use of the
addressee only, and is confidential and may be the subject of legal
professional privilege. Any dissemination, distribution, copying or use
of this communication without permission of the addressee is strictly
prohibited. The views expressed in this communication may not
necessarily be the views held by Piper Group plc



<Prev in Thread] Current Thread [Next in Thread>