Hi:
I'm correcting the two bugs, the first one is when a "lookfor keyword"
has no value, like in this test case, there's no value corresponding
to ENTIDADE_K in $textwhere
<xsl:template match="/">
<xsl:call-template name="replace-values">
<xsl:with-param name="textfrom"
select="'list_entidadeprocessos.aspx?k=PAI&entidade_k={ENTIDADE_K}&processo_k={PROCESSO_K}'"/>
<xsl:with-param name="textwhere"
select="'?businessclass=PROCESSO&ENTIDADE_K=&processo_k=xx0001'"/>
</xsl:call-template>
</xsl:template>
but i'm not happy with the solution, it does not folow a straight
logic, it's what we call "martelada" in my language... How can i have
a more "elegant" solution?
<xsl:template name="replace-values">
<xsl:param name="textfrom"/>
<xsl:param name="textwhere"/>
<!--xsl:variable name="textfrom"
select="concat($textfrom0,'&')"/-->
<xsl:variable
name="lower">abcdefghijklmnopqrstuvwxyz</xsl:variable>
<xsl:variable
name="upper">ABCDEFGHIJKLMNOPQRSTUVWXYZ</xsl:variable>
<xsl:choose>
<xsl:when test="contains($textfrom, '{')">
<xsl:variable name="lookfor"
select="substring-before(substring-after($textfrom,'{'),'}')"/>
<xsl:variable name="before"
select="substring-before($textfrom,
concat('{',$lookfor,'}'))"/>
<xsl:variable name="after"
select="substring-after($textfrom,
concat('{',$lookfor,'}'))"/>
<xsl:variable name="value">
<xsl:variable name="ulookfor"
select="translate($lookfor, $lower,
$upper)"/>
<xsl:variable name="llookfor"
select="translate($lookfor, $upper,
$lower)"/>
<xsl:variable name="utextwhere"
select="translate($textwhere,
$lower, $upper)"/>
<xsl:variable name="ltextwhere"
select="translate($textwhere,
$upper, $lower)"/>
<xsl:choose>
<xsl:when
test="substring-before(substring-after($utextwhere,concat($ulookfor,'=')),'&')">
<xsl:value-of
select="substring-before(substring-after($utextwhere,
concat($ulookfor,'=')),'&')"/>
</xsl:when>
<xsl:when
test="substring-before(substring-after($ltextwhere,concat($llookfor,'=')),'&')">
<xsl:value-of
select="substring-before(substring-after($ltextwhere,
concat($llookfor,'=')),'&')"/>
</xsl:when>
<xsl:when
test="substring-after($utextwhere, concat($ulookfor,'='))">
--------------------------------------> <xsl:variable
name="stest"
select="substring-after($utextwhere, concat($ulookfor,'='))"/>
<xsl:if
test="not(starts-with($stest,'&'))">
<xsl:value-of
select="substring-after($utextwhere,
concat($ulookfor,'='))"/>
</xsl:if>
</xsl:when>
<xsl:when
test="substring-after($ltextwhere, concat($llookfor,'='))">
--------------------------------------> <xsl:variable
name="stest"
select="substring-after($ltextwhere, concat($llookfor,'='))"/>
<xsl:if
test="not(starts-with($stest,'&'))">
<xsl:value-of
select="substring-after($ltextwhere,
concat($llookfor,'='))"/>
</xsl:if>
</xsl:when>
</xsl:choose>
</xsl:variable>
<xsl:value-of select="$before"/>
<xsl:value-of select="$value"/>
<xsl:call-template name="replace-values">
<xsl:with-param name="textfrom"
select="$after"/>
<xsl:with-param name="textwhere"
select="$textwhere"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$textfrom"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
On 06/02/06, António Mota <amsmota(_at_)gmail(_dot_)com> wrote:
I wrote this special case of string replace and tought to post this to
go to the list archives, maybe it'll be usefull to someone.
It's used to replace some keywords in a url-like string with the
results from another url-like string, for example, with
list_entidadeprocessos.aspx?k=PAI&entidade_k={ENTIDADE_K}&processo_k={PROCESSO_K}
and
?businessclass=PROCESSO&k=K00047&processo_k=XX0001'
will give
list_entidadeprocessos.aspx?k=PAI&entidade_k=K00047&processo_k=XX0001
In my concrete case the first string is retrieved from a database
where some app definitions are stored, and the secons is the qwery
string of the actual page where the transformation is being made.
It has two minor bugs that none of the users have found, i'll fix then
one of theses days :)
<xsl:template name="replace-values">
<xsl:param name="textfrom"/>
<xsl:param name="textwhere"/>
<xsl:variable
name="lower">abcdefghijklmnopqrstuvwxyz</xsl:variable>
<xsl:variable
name="upper">ABCDEFGHIJKLMNOPQRSTUVWXYZ</xsl:variable>
<xsl:choose>
<xsl:when test="contains($textfrom, '{')">
<xsl:variable name="lookfor"
select="substring-before(substring-after($textfrom,'{'),'}')"/>
<xsl:variable name="before"
select="substring-before($textfrom,
concat('{',$lookfor,'}'))"/>
<xsl:variable name="after"
select="substring-after($textfrom,
concat('{',$lookfor,'}'))"/>
<xsl:variable name="value">
<xsl:variable name="ulookfor"
select="translate($lookfor, $lower,
$upper)"/>
<xsl:variable name="llookfor"
select="translate($lookfor, $upper,
$lower)"/>
<xsl:variable name="utextwhere"
select="translate($textwhere,
$lower, $upper)"/>
<xsl:variable name="ltextwhere"
select="translate($textwhere,
$upper, $lower)"/>
<xsl:choose>
<xsl:when
test="substring-before(substring-after($utextwhere,concat($ulookfor,'=')),'&')">
<xsl:value-of
select="substring-before(substring-after($utextwhere,
concat($ulookfor,'=')),'&')"/>
</xsl:when>
<xsl:when
test="substring-before(substring-after($ltextwhere,concat($llookfor,'=')),'&')">
<xsl:value-of
select="substring-before(substring-after($ltextwhere,
concat($llookfor,'=')),'&')"/>
</xsl:when>
<xsl:when
test="substring-after($utextwhere, concat($ulookfor,'='))">
<xsl:value-of
select="substring-after($utextwhere,
concat($ulookfor,'='))"/>
</xsl:when>
<xsl:when
test="substring-after($ltextwhere, concat($llookfor,'='))">
<xsl:value-of
select="substring-after($ltextwhere,
concat($llookfor,'='))"/>
</xsl:when>
</xsl:choose>
</xsl:variable>
<xsl:value-of select="$before"/>
<xsl:value-of select="$value"/>
<xsl:call-template name="replace-values">
<xsl:with-param name="textfrom"
select="$after"/>
<xsl:with-param name="textwhere"
select="$textwhere"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$textfrom"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--