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

RE: How can I do a string substitution for turning ent

Subject: RE: How can I do a string substitution for turning entities into html tags -> Thx Jim
From: "Bill Chmura" <Bill@xxxxxxxxxxxxx>
Date: Thu, 17 Apr 2003 11:11:42 -0400
xsl string substitution
Thanks for the code sample!  You have managed to save the last bit of
sanity I had left.


-----Original Message-----
From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
[mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Jim Hart
Sent: Wednesday, April 16, 2003 8:29 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re:  How can I do a string substitution for turning
entities into html tags



On Tuesday, April 15, 2003, at 05:37  PM, Bill Chmura wrote:

>
>
> Here is an example of my xml data
>
> <text>
>    &lt;p&gt;Sometext here. Followed by more text&lt;/p&gt;
>    &lt;p&gt;More text.&lt;/p&gt;
>    &lt;li&gt;For more info see &lt;/li&gt;
> </text>
>
>
This turns the tags into elements so you can do other things with them 
if you want to. Note that the elements must have open and close tags.

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
version="1.0">
<xsl:template match="/">
	<xsl:apply-templates select="*"/>
</xsl:template>
<xsl:template match="text">
	<xsl:call-template name="makeElements">
		<xsl:with-param name="string"><xsl:value-of
select="text()"/>
		</xsl:with-param>
	</xsl:call-template>
</xsl:template>
<xsl:template name="makeElements">
	<xsl:param name="string"/>
	<xsl:choose>
	<xsl:when test="contains($string,'&lt;')">
		<xsl:value-of
select="substring-before($string,'&lt;')"/>
		<xsl:call-template name="makeElement">
			<xsl:with-param name="string">
				<xsl:value-of
select="substring-after($string,'&lt;')"/>
			</xsl:with-param>
		</xsl:call-template>
	</xsl:when>
	<xsl:otherwise>
		<xsl:value-of select="$string"/>
	</xsl:otherwise>
	</xsl:choose>
</xsl:template>
<xsl:template name="makeElement">
	<xsl:param name="string"/>
	<xsl:element name="{substring-before($string,'&gt;')}">
		<xsl:value-of 
select="substring-before(substring-after($string,'&gt;'),'&lt;')"/>
	</xsl:element>
	<xsl:call-template name="makeElements">
		<xsl:with-param name="string">
			<xsl:value-of 
select="substring-after(substring-after($string,'&gt;'),'&gt;')"/>
		</xsl:with-param>
	</xsl:call-template>
</xsl:template>
</xsl:stylesheet>



Jim Hart, Project Manager
Academic Technology Services
Library and Information Services
Bates College
Lewiston, Maine, USA


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


 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.