RE: [xsl] Generic template for collapsing arbitrary length runs o f same tag into one tag?

Subject: RE: [xsl] Generic template for collapsing arbitrary length runs o f same tag into one tag?
From: "McNally, David" <David.McNally@xxxxxxxxxx>
Date: Thu, 15 Aug 2002 14:26:21 -0400
This should do it:

<xsl:template match="i">
	<xsl:if test="not(name(preceding-sibling::node()[1])='i')">
		<i>
			<xsl:apply-templates/>
			<xsl:if test="name(following::node()[1])='i'">
				<xsl:apply-templates
select="following::node()[1]" mode="following"/>
			</xsl:if>
		</i>
	</xsl:if>
</xsl:template>

<xsl:template match="i" mode="following">
	<xsl:apply-templates/>
	<xsl:if test="name(following::node()[1])='i'">
		<xsl:apply-templates select="following::node()[1]"
mode="following"/>
	</xsl:if>
</xsl:template>

Seems to work in Saxon 6.5.2.

Hope this helps,
David.



> -----Original Message-----
> From: Richard Bondi [mailto:rbondi@xxxxxxxxxx]
> Sent: Thursday, August 15, 2002 1:00 PM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] Generic template for collapsing arbitrary 
> length runs of
> same tag into one tag?
> 
> 
> [This is hopefully a clearer re-post of a post that was understood 
> differently be different people.]
> 
> Dear All,
> 
> Consider the following example xml:
> 
> <root>
> 	<Paragraph>While <Characters>S. cerevisiae</Characters> 
> is the most 
> commonly studied yeast, it is not the only yeast that has 
> been studied.  Two
> 	<i>o</i><i>t</i><i>h</i><i>e</i><i>r</i>
> yeasts have also been studied to an
> 	
> <i>e</i><i>x</i><i>t</i><i>e</i><i>n</i><i>s</i><i>i</i><i>v</
> i><i>e</i>
> degree.  First, studies of <Characters>Schizosaccharomyces 
> pombe</Characters> have made extremely important contributions to our 
> understanding of the eukaryotic cell cycle.
> </Paragraph>
> </root>
> 
> This needs to be transformed to:
> 
> <root>
> 	<Paragraph>While <Characters>S. cerevisiae</Characters> 
> is the most 
> commonly studied yeast, it is not the only yeast that has 
> been studied.  Two
> <i>other</i>
> 	yeasts have also been studied to an
> <i>extensive</i>
> 	degree.  First, studies of <Characters>Schizosaccharomyces 
> pombe</Characters> have made extremely important contributions to our 
> understanding of the eukaryotic cell cycle.
> </Paragraph>
> </root>
> 
> This is an extract. Throughout the manuscript, there are runs of 
> unpredictable length of always adjacent <i> tags. I cannot 
> come up with a 
> template which will collapse any such arbitrary-length run of 
> adjacent <i>s 
> into a single <i> tag. Can anyone here?
> 
> MTIA,
> Richard Bondi
> 
> 
> Keywords for archive search engine:
> merge tags, merging tags, collapse tags
> 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 


---------------------------------------

The information contained in this e-mail message, and any attachment thereto, is confidential and may not be disclosed without our express permission.  If you are not the intended recipient or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that you have received this message in error and that any review, dissemination, distribution or copying of this message, or any attachment thereto, in whole or in part, is strictly prohibited.  If you have received this message in error, please immediately notify us by telephone, fax or e-mail and delete the message and all of its attachments.  Thank you.

Every effort is made to keep our network free from viruses.  You should, however, review this e-mail message, as well as any attachment thereto, for viruses.  We take no responsibility and have no liability for any computer virus which may be transferred via this e-mail message.


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


Current Thread