xsl-list
[Top] [All Lists]

Re: [xsl] Modify Value of a Parameter Globally Within a Template

2012-11-12 12:45:17

On 12/11/2012 18:20, Lisa Jiang wrote:
Hi Michael,

Yes so the input is information that I get from an HTTP request. This
information consists of a descriptor that tells whether our query for
the website was a match for the information on the website. It also
consists of information from the website. I then need to process the
information based on the descriptor. However, sometimes the descriptor
is incorrect. So I first want to call another template to check
whether or not the descriptor is correct based on the information and
change it if it is incorrect, since it affects processing later on. At
output, I generate a comment based on the descriptor as well as the
website information post-processing.

OK, great.

The functional approach to this is a pipeline.

First compute the "corrected descriptor" in a variable. If the descriptor is already correct, this is trivially the same as the input descriptor. If the input descriptor is incorrect, then the correct descriptor is some transformation of the input descriptor.

Then do some processing using the corrected descriptor as input.

Schematically:

<xsl:variable name="correctedDescriptor"
select="if (f:descriptorIsCorrect($descriptor)) then $descriptor else f:applyCorrection($descriptor)"/>

<xsl:template match="/">
  <xsl:sequence select="f:doTheWork(., $correctedDescriptor)"/>
</xsl:template>

I've written this using functions rather than templates for brevity but the logic is the same either way.

Michael Kay
Saxonica


So for example:
Our query
Brand: Haagen Daaz
Flavor: Chocolate
Price: $5.99

Website return:
Descriptor: Found
Brand: Haagen Dazs
Price: $5.99

The descriptor should say "Similar Found." So then I would check
whether or not the brand names are exactly the same, and, if not, I
would change the descriptor.

So then instead of outputting (incorrectly):
Descriptor: Found
Comment: Exact match
Brand: Haagen Daaz
Price: $5.99

The correct output would be:
Descriptor: Similar Found
Comment: Error in brand name
Brand: Haagen Dazs
Price: $5.99

Thanks!
Lisa


-------- Original Message --------
Subject: Re: [xsl] Modify Value of a Parameter Globally Within a Template
Date: Mon, 12 Nov 2012 17:21:55 +0000
From: Michael Kay <mike(_at_)saxonica(_dot_)com>
Reply-To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com


On 12/11/2012 17:07, Lisa Jiang wrote:
Dear All,

Is there a specific way to change the value of a parameter within a
call to another template and then use the resulting value for tests in
the original template? Or just change the value of a parameter within
a template that then reflects globally? I've included some simple,
example code on what I would like to do.


No, you can't do it this way: this isn't the way functional languages work.

If you can step up a couple of levels and describe the problem (that is,
the input and output of the transformation and their relationship to
each other) then we can try and find the right approach for you.

Michael Kay
Saxonica

--~------------------------------------------------------------------
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>
--~--

--~------------------------------------------------------------------
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>
--~--




--~------------------------------------------------------------------
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>
--~--