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

RE: preceding/following character?

Subject: RE: preceding/following character?
From: "Andrew Welch" <ajwelch@xxxxxxxxxxxxxxx>
Date: Fri, 17 Jun 2005 08:58:27 +0100
RE:  preceding/following character?
> Say I have source with mixed content like:
>
> <foo>Some text and more text <bar/>. Some more text.</foo>
>
> I need a "bar" matched template that will under certain
> conditions move
> that period that immediately follows the element to be ahead it.
>
> E.g., in some conditions, output would be:
>
> <foo_out>Some text and more text.<bar_out/> Some more text.</foo_out>
>
> This seems like a simple problem, but I can't really fathom how to
> solve it.  I'm using XSLT 2.0.

How about:

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

<xsl:template match="text()[preceding-sibling::*[1][self::bar]]">
	<xsl:choose>
		<xsl:when test="substring(.,1,1) = '.'">
			<xsl:text/>.<bar_out/>
			<xsl:value-of select="substring(.,2)"/>
		</xsl:when>
		<xsl:otherwise>
			<xsl:value-of select="."/>
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>

When applied to:

<foo>Some text and more text <bar/>. Some more text.</foo>

Results in:

<div>Some text and more text .<bar_out/> Some more text.</div>

cheers
andrew

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.