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

Re: Patterns and scoped variables (or rather lack the

Subject: Re: Patterns and scoped variables (or rather lack thereof)
From: Ihe Onwuka <ihe.onwuka@xxxxxxxxx>
Date: Wed, 19 Feb 2014 09:34:35 +0000
Re:  Patterns and scoped variables (or rather lack  the
I see, you eliminate the multiple tokenize calls by encapsulating the
logic in a function which is called in the pattern.

Nice.

On Mon, Feb 17, 2014 at 5:15 PM, Wendell Piez <wapiez@xxxxxxxxxxxxxxx> wrote:
> Ihe,
>
> I will sometimes resort to stylesheet functions to provide
> encapsulation of logic like this.
>
> So (designed to return nothing when the input doesn't show two values
> when tokenized on the colon):
>
> <xsl:function name="ihe:colon-delimited-label" as="xs:string()?">
>   <xsl:param name="field" as="node()"/>
>   <xsl:variable name="split-on-colon" select="tokenize($field,'\s*:\s*')"/>
>   <xsl:if test="count($split-on-colon) eq 2">
>     <xsl:sequence select="$split-on-colon[1]"/>
>   <xsl:if>
> </xsl:function>
>
> So
>
> <xsl:template match="text()[count(tokenize(ihe:colon-delimited-label(.)),'\s*')
> le 3]">
>   ...
>
> I hope that helps,
> Wendell
>
>
> On Sat, Feb 15, 2014 at 3:42 PM, Ihe Onwuka <ihe.onwuka@xxxxxxxxx> wrote:
>> Transforming this sort of markup
>>
>> <div class="fr small subtle">Transaction date: Sep 26, 2013</div>
>>
>> into a key value pair.
>>
>> <Transactiondate>Sep 26, 2013</Transactiondate>
>>
>> However if there are too many words before the colon separator (the
>> key part) then it probably isn't suitable for the key value treatment
>> (the code below uses 3 words as the cutoff point).
>>
>> Talking of the code below and the thread title, the issue is how many
>> times I've had to (or think I've had to ) tokenize the string on colon
>> because I cannot (or think I cannot) introduce a let scoped variable
>> into the pattern.
>>
>>
>>  <xsl:template match="text()[count(tokenize(.,':')) eq 2 and
>> count(tokenize(tokenize(.,':')[1],'\s+')) lt 4]">
>>
>>     <xsl:variable name="keyValue" select="tokenize(.,':')"/>
>>
>>     <xsl:element name="{replace($keyValue[1],'\s+','')}"> .....key.....
>>       <xsl:value-of select="$keyValue[2]"/>
>> ......value.....
>>     </xsl:element>
>>
>>   </xsl:template>
>>
>> How else do I think I could do this.
>>
>> <xsl:template match="text()">
>>   <xsl:call-template name="dealWithText"
>> </xsl:template>
>>
>> <xsl:template name="dealWithText">
>>   <xsl:variable name="keyValue" select=tokenize ...etc>
>>   <xsl:choose>
>>     <xsl:when etc
>>
>> which of course camouflages the matchng rule inside the call template.
>>
>> Is this the best that can be done  or have I missed something.
>>
>
>
>
> --
> Wendell Piez | http://www.wendellpiez.com
> XML | XSLT | electronic publishing
> Eat Your Vegetables
> _____oo_________o_o___ooooo____ooooooo_^

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.