[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
Re: [xsl] Modify Value of a Parameter Globally Within a Template
Subject: Re: [xsl] Modify Value of a Parameter Globally Within a Template From: Lisa Jiang <ljiang@xxxxxxxxx> Date: Tue, 13 Nov 2012 13:08:08 -0500 |
That approach worked perfectly. Thank you for all the help! On Mon, Nov 12, 2012 at 1:45 PM, Michael Kay <mike@xxxxxxxxxxxx> wrote: > > 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@xxxxxxxxxxxx> >>> Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx >>> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx >>> >>> >>> 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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Modify Value of a Paramet, Michael Kay | Thread | [xsl] "redirect" xml-stylesheet pro, Hermann Stamm-Wilbra |
Re: [xsl] Printing a page header ba, Wendell Piez | Date | [xsl] priority of key patterns, Ihe Onwuka |
Month |