Re: [xsl] What todo when execution order becomes important? I.e.: with text data and filters

Subject: Re: [xsl] What todo when execution order becomes important? I.e.: with text data and filters
From: Abel Braaksma <abel.online@xxxxxxxxx>
Date: Wed, 20 Dec 2006 10:48:17 +0100
David Carlisle wrote:
If you post an example of some code that produces results in the wrong
order, we can suggest ways to change it, but otherwise I'm not sure what
to suggest.

Dimitre Novatchev wrote:
f(g(x))

will first apply g() on x and then apply f() on the result.


Thanks for your replies.

Dimitre, I believe that is indeed what I did: recursive calling a function (template). I will look into FXSLT
David, I thought the example would proof my point, but I see now that it neither runs nor shows my point when you get it running.


So, I tried to make a small self-contained bogus project that can run on itself. The result you find below. It, however, does not proof my point in that the order of execution is of influence to the results when re-applying regular expressions and analyze-string to the same set of textual data.

With your information applied, I believe it is an error somewhere in the original project (likely), or a bug in Saxon (unlikely).

If you run the example below, the first string will correctly translate to "string with some new data", others will be left untouched. The messages will show in some order, in my case (from bottom up):

1) Applying filter: five 2) Applying filter: five 3) Applying filter: five 4) Applying filter: four 5) Applying filter: four 6) Applying filter: four 7) Applying filter: one 8) Applying filter: one 9) Applying filter: one 10) Applying filter: six 11) Applying filter: six 12) Applying filter: three
13) Applying filter: three
14) Applying filter: three
15) Applying filter: two
16) Applying filter: two
17) Applying filter: two



Cheers, -- Abel



<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:output method="xml" indent="yes"/>


<xsl:template match="/" >
<xsl:variable name="texts">
<text>string xyzith zzzzome daaaza</text>
<text>just some free text here</text>
<text>and more of this free text now</text>
</xsl:variable>
<xsl:apply-templates select="$texts/text" mode="texts"></xsl:apply-templates>
</xsl:template>
<xsl:template match="*" mode="texts">
<xsl:text>&#xA;</xsl:text>
<xsl:call-template name="apply-filter">
<xsl:with-param name="filter" select="$filter/filter[1]" />
<xsl:with-param name="value" select=" . " />
</xsl:call-template> </xsl:template>
<xsl:variable name="filter">
<filter name="one" find="aaz" replace="t" />
<filter name="two" find="xyz" replace="w" />
<filter name="three" find="z+" replace="s" />
<filter name="four" find="data" replace="blabla" />
<filter name="five" find="blabla" replace="xantippe" />
<filter name="six" find="xantippe" replace="new data" />
</xsl:variable>
<xsl:template name="apply-filter" xpath-default-namespace="">
<xsl:param name="value" />
<xsl:param name="filter" />
<xsl:message select="concat('Applying filter: ', $filter/@name)" />
<xsl:variable name="single-filter-result">
<xsl:analyze-string select="$value" regex='{$filter/@find}'>
<xsl:matching-substring>
<xsl:value-of select="replace(., $filter/@find, $filter/@replace)" />
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:value-of select="." />
</xsl:non-matching-substring>
</xsl:analyze-string> </xsl:variable>
<xsl:variable name="multi-filter-result">
<xsl:choose>
<xsl:when test="$filter/following-sibling::filter">
<xsl:call-template name="apply-filter">
<xsl:with-param name="value" select="$single-filter-result" />
<xsl:with-param name="filter" select="$filter/following-sibling::filter[1]" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$single-filter-result" />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:value-of select="$multi-filter-result" />
</xsl:template>
</xsl:stylesheet>


Current Thread