[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Matching certain elements following an element

Subject: Re: Matching certain elements following an element
From: Ramon Buckland <ramon@xxxxxxxxxxxxxxx>
Date: Thu, 10 Nov 2005 00:41:31 +1100
ramon buckland
Hi Matthew,

I am sure someone else on this list could do a better job,
code a far elebant solution, but this does
work with the sample you gave.

    <xsl:param name="section" select="'bar'"/>
    
    <xsl:template match="/">
        
        <!-- dump put what the following h2 is -->
        <xsl:message><xsl:value-of select="//h2[a/text() =
$section]/following::h2"/></xsl:message>
        
        <!-- select Only the nodes that are following-siblings of me, or
                of my ancestor (not my child or their child nodes, they
cop-of will do that for me) .. 
               where they have a h2 element that follows, that has the
same id as the one
              following the section we are interested in 
        -->
        <xsl:copy-of select="//h2[a/text() =
$section]/ancestor::*/following-sibling::*
            [
            (generate-id(following::h2[1]) = generate-id(//h2[a/text() =
$section]/following::h2[1]))
            ]
            
            |
            
            //h2[a/text() = $section]/following-sibling::*
            [
            (generate-id(following::h2[1]) = generate-id(//h2[a/text() =
$section]/following::h2[1]))
            ]
            
            "/>
        
    </xsl:template>


Regards .. 
Ramon
On Fri, 2005-11-04 at 12:24 -0800, Matthew Fonda wrote:
> Hello,
> 
> I have an interesting problem here, and I am unsure how to go about 
> solving it.
> 
> I have the following xml:
> 
> <f>
>     <b>
>         <h2><a>foo</a></h2>
>         <p>......</p>
>         <p>......</p>
>         <p>......</p>
>         <img>....</img>
>         <p>......</p>
>         <div>
>             <h2><a>bar</a></h2>
>             <ul>
>                 <li>.....</li>
>                 <li>.....</li>
>                 <li>.....</li>
>                 <li>.....</li>
>             </ul>
>             <p>...</p>           
>             <h2><a>baz</a></h2>
>         </div>
>         <foo>....</foo>
>         <a>......</a>
>         <p>......</p>
>         <p>......</p>
>         <baz/>
>     </b>
> </f>
> 
> I need to pass the template a parameter, I will call this $section, and then I need the stylesheet to return whatever is in that section. So for example, if $section = 'foo', it would match the h2/a/text() = foo, and return everything up to the next h2/a. So it would return:
>   <p>......</p>
>   <p>......</p>
>   <p>......</p>
>   <img>....</img>
>   <p>......</p>
> 
> Or if $section = 'baz', I need to get:
>   <foo>....</foo>
>   <a>......</a>
>   <p>......</p>
>   <p>......</p>
>   <baz/>
> 
> And so on. Now, the problem is, there is <div> elements mixed in there. I want to completely ignore these. Any ideas on how I could go about achieving this?
> 
> Thanks,
> -- Matthew

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.