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

Xpath related to following-sibling and preceding-sibli

Subject: Xpath related to following-sibling and preceding-sibling
From: "Teresa Rippeon" <teresa.rippeon@xxxxxxxxxxxxxxx>
Date: Tue, 5 Aug 2003 14:42:07 -0400
xpath group by
I have the following example XML data with the desired output:

<Block id="block1">
<BlockContent>

<Para>This is para 1 in group 1</Para>
<Para>This is para 2 in group 1</Para>

<list><li>List item 1</li><li>List item 2</li></list>

<Para>This is para 1 in group 2</Para>
<Para>This is para 2 in group 2</Para>
<Para>This is para 3 in group 2</Para>
<Para>This is para 4 in group 2</Para>

</BlockContent>
</Block>

With the following desired output:

<description id="Block1_P1">
<p>This is para 1 in group 1</p>
<p>This is para 2 in group 1</p>
</description>

<list> .... </list>

<description id="Block1_P4">
<p>This is para 1 in group 2</p>
<p>This is para 2 in group 2</p>
<p>This is para 3 in group 2</p>
<p>This is para 4 in group 2</p>
</description>

I have the following portion of the XSLT, which generates...

<description id="Block1_P1">
<p>This is para 1 in group 1</p>
<p>This is para 2 in group 1</p>
<p>This is para 1 in group 2</p>
<p>This is para 2 in group 2</p>
<p>This is para 3 in group 2</p>
<p>This is para 4 in group 2</p></description>
<list> .... </list>

I know that I should have a check for a following-sibling that is not a
Para, but as yet I have not been able to come up with the correct Xpath
expression to complete this. Any suggestions? Thanks!

<xsl:for-each
select="//BlockContent/Para|//BlockContent/List|//BlockContent/Table">

	<!-- PARAs -->
	<xsl:if test="self::Para"> 	

		<xsl:choose>

			<!-- When the preceding sibling was a para, then
the description element has already been established
			       and the para was appended into the
description element in a previous for loop; don't want to write
			       it out again -->
			<xsl:when test="preceding-sibling::Para">
			</xsl:when>

			<!-- Otherwise, establish the description
element and put all consecutive paras within it as a chunk -->
			<xsl:otherwise>
				<xsl:call-template
name="FormatXMLOutput"/>

				<xsl:element name="description">

					<xsl:attribute
name="identifier">
						<xsl:value-of
select="ancestor::Block[1]/@ID"/>
						<xsl:text>_P</xsl:text>
						<xsl:number count="Para"
from="BlockContent" level="single"/>
					</xsl:attribute>

					<xsl:call-template
name="FormatXMLOutput"/>

					<xsl:element name="p">
						<xsl:apply-templates/>
					</xsl:element>

					<!-- Now loop through all of the
siblings of the Para so that all consecutive paras are "chunked"
together in 
					      the description element.
Note that the siblings are defined as on the same level so if there was
a list
					      between this para and the
previous sibling para, then you don't want this in the same description
					      element "chunk" -->

					<xsl:for-each
select="following-sibling::Para">
						<xsl:element name="p">
	
<xsl:apply-templates/>
						</xsl:element>
					</xsl:for-each>


				</xsl:element>

			</xsl:otherwise>

		</xsl:choose>    				

	</xsl:if>  

Etc. specifically dealing with lists, tables, etc.

Thanks!


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.