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

RE: Something like eval()? and Lookup Tables

Subject: RE: Something like eval()? and Lookup Tables
From: "McKeever, Marty" <marty.mckeever@xxxxxxxxxxxxxxxxx>
Date: Wed, 07 Nov 2001 13:11:10 -0500
xsl select eval
I wound up solving my own eval() problem, using the lookup table device.
Nifty indeed.

Heres what i came up with--

Input: <foo
hyperLink="some.htm?one={$one}&amp;two={$two}&amp;three={$three}">click
me</foo>

OutPut: <a href="some.htm?one=uno&two=dos&three=tres">click me</a>

Stylesheet:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
exclude-result-prefixes="msxsl">

<xsl:param name="one">uno</xsl:param>
<xsl:param name="two">dos</xsl:param>
<xsl:param name="three">tres</xsl:param>
<xsl:param name="four">quattro</xsl:param>

<xsl:variable name="lookupTable">
<table>
<item name="one"><xsl:value-of select="$one"/></item>
<item name="two"><xsl:value-of select="$two"/></item>
<item name="three"><xsl:value-of select="$three"/></item>
<item name="four"><xsl:value-of select="$four"/></item>
</table>
</xsl:variable>


<xsl:template match="foo">
<a>
<xsl:attribute name="href">
<xsl:call-template name="matchParams">
<xsl:with-param name="inputString" select="@hyperLink"/>
</xsl:call-template>
</xsl:attribute>
<xsl:value-of select="."/>
</a>
</xsl:template>


<xsl:template name="matchParams">
<xsl:param name="limit">100</xsl:param>
<xsl:param name="inputString"/>
<xsl:variable name="flagged"><xsl:if
test="contains($inputString,'{$')"><xsl:value-of
select="substring-after(substring-before($inputString,'}'),'{$')"/></xsl:if>
</xsl:variable>
<xsl:variable name="resultString">
<xsl:choose>
	<xsl:when test="$flagged!=''">
	<xsl:call-template name="replace">
	<xsl:with-param name="str" select="$inputString"/>
	<xsl:with-param name="from" select="concat('{$',$flagged,'}')"/>
	<xsl:with-param name="to"
select="msxsl:node-set($lookupTable)/table/item[@name=$flagged]"/>
	</xsl:call-template>
	</xsl:when>
	<xsl:otherwise><xsl:value-of select="$inputString"/></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:choose>
	<xsl:when test="contains($resultString,'{$') and $limit &gt; 0">
	<xsl:call-template name="matchParams">
	<xsl:with-param name="limit" select="$limit - 1"/>
	<xsl:with-param name="inputString" select="$resultString"/>
	</xsl:call-template>
	</xsl:when>
	<xsl:otherwise><xsl:value-of
select="$resultString"/></xsl:otherwise>
</xsl:choose>
</xsl:template>


<!-- Search & Replace -->
<xsl:template name="replace">
<xsl:param name="str" select="."/>
<xsl:param name="from"/>
<xsl:param name="to"/>
<xsl:choose>
	<xsl:when test="not($from) or not($to)"><xsl:value-of
select="$str"/></xsl:when>
	<xsl:otherwise>
		<xsl:variable name="result"><xsl:value-of
select="substring-after($str,$from)"/></xsl:variable>
		<xsl:value-of
select="substring-before($str,$from)"/><xsl:value-of select="$to"/>
		<xsl:choose>
			<xsl:when test="contains($result,$from)">
			<xsl:call-template name="replace">
			<xsl:with-param name="str"><xsl:value-of
select="$result"/></xsl:with-param>
			<xsl:with-param name="from"><xsl:value-of
select="$from"/></xsl:with-param>
			<xsl:with-param name="to"><xsl:value-of
select="$to"/></xsl:with-param>
			</xsl:call-template>
			</xsl:when>
			<xsl:otherwise><xsl:value-of
select="$result"/></xsl:otherwise>
		</xsl:choose>
	</xsl:otherwise>
</xsl:choose>
</xsl:template>


</xsl:stylesheet>
> 

 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.