Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 7th, 2006, 04:05 AM
Registered User
 
Join Date: Sep 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to select these nodes?

here is html code:

<html>
<body>
<h1>Chapter 1</h1>
<p>Then with expanded wings he steers his flight</p>
<p>Aloft, incumbent on the dusky Air</p>
<p>the cloud is white</p>
<h1>Chapter 1, Section 1</h1>
<p>That felt unusual weight, till on dry Land</p>
<p>He lights, if it were Land that ever burned</p>
</body>
</html>

I want to get the nodes <p> between the first <h1>element and the second <h1> (dont know
how many <p> nodes there are)

the result is:
<p>Then with expanded wings he steers his flight</p>
<p>Aloft, incumbent on the dusky Air</p>
<p>the cloud is white</p>


what i thought is:
use "following-sibling" and check each node's elementname whether the name is <h1>
if true then stop apply-template
but i don't konw how to write it?

any ideas? thanks!

 
Old September 7th, 2006, 04:15 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Searching for "XSLT positional grouping" will give you some clues. In XSLT 2.0,

<xsl:for-each-group select="*" group-starting-with="h1">

In 1.0 a common approach is

<xsl:variable name="second-h1" select="generate-id(h1[2])">
<xsl:for-each select="p[generate-id(following-sibling::h1[1]) = $second-h1]">

or in this case its simpler.

<xsl:for-each select="h1[2]/preceding-sibling::p">

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
To Select a specific nodes from XML vkommera XSLT 4 June 27th, 2008 03:39 PM
Select row in GridView WITHOUT using Select button rao965 ASP.NET 2.0 Professional 1 February 15th, 2008 10:44 AM
Select nodes randomly carlosaml XSLT 3 October 17th, 2007 10:18 AM
Fill select box and select recordset value markd Classic ASP Databases 1 February 20th, 2006 06:41 PM
Help: Select every node except these nodes arcuza XSLT 8 May 25th, 2005 08:07 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.