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

RE: FW: Dealing with mixed content

Subject: RE: FW: Dealing with mixed content
From: "Paul Clarke" <pclarke@xxxxxxxxxxxxxxxx>
Date: Wed, 16 Feb 2005 12:59:39 -0000
paul clarke
Hello Joris,

Thank you for your prompt reply. The solution works well.

Being new to XSLT I'm a little unsure of exactly what the pattern in the
'use' attribute value in the xsl:key element is doing.

Could you please explain  it in a little more detail.

Thanks

Paul 

-----Original Message-----
From: Joris Gillis [mailto:roac@xxxxxxxxxx] 
Sent: 15 February 2005 18:48
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re:  FW: Dealing with mixed content

Tempore 19:31:36, die 02/15/2005 AD, hinc in xsl-list@xxxxxxxxxxxxxxxxxxxxxx
scripsit Paul Clarke
<pclarke@xxxxxxxxxxxxxxxx>:

> Hello,
>
> Apologies inadvance for the 'XSL 101' nature of this question but I'm 
> new to XSL.
>
> I receive XML from an automate conversion process, over which I have 
> no control.
>
> Example:
>
> 	<block >Text <font font-weight="bold">more text</font> more 
> text<sr/>more text. <hr/>more text <sr/>more text.</block>
>
> The <sr/> elements can be ignored but the <hr/> element indicates that 
> an exisitng <P> element should be terminated and a new <P> element
started.
>
> From the above sample the output would be:
>
> 	<P>Text <f>more text</f> more text more text. </P>
> 	<P>more text more text</P>
>
Hi,

This is a grouping problem. Numerous techniques are available for solving
problems like this.

Here you have one:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  
version="1.0">
<xsl:output method="xml" indent="yes"/>

<xsl:key name="group" match="node()" use="generate-id((.. |
preceding-sibling::hr)[last()])"/>

<xsl:template match="block">
	<xsl:copy>
		<xsl:for-each select="hr|.">
			<p>
				<xsl:apply-templates
select="key('group',generate-id())"/>
			</p>
		</xsl:for-each>
	</xsl:copy>
</xsl:template>

<xsl:template match="sr | hr"/>

<xsl:template match="font">
	<f>
		<xsl:apply-templates/>
	</f>
</xsl:template>

</xsl:stylesheet>


regards,
--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-view.cgi?userid=38041)
Spread the wiki (http://www.wikipedia.org)

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.