xsl-list
[Top] [All Lists]

Re: [xsl] Patterns and scoped variables (or rather lack thereof)

2014-02-16 11:05:56
No I am not using 3.0 it is good to know that this facility is available there.

On Sun, Feb 16, 2014 at 5:01 PM,  <abel(_at_)exselt(_dot_)net> wrote:
It depends whether you are using XSLT 3.0 or not, but since you mention 
Let-expressions, I think you mean indeed that you are using XSLT 3.0, since 
these were not available earlier.

The Pattern Syntax (see http://www.w3.org/TR/xslt-30/#pattern-syntax) clearly 
allows a predicate with a Let expression. Whether or not this is already 
implemented in the processor you use, I wouldn't know.

For instance, you match expression could become:

<xsl:template match="text()[
    let $t := tokenize(., ':')
    return
       count($t) eq 2 and
       count(tokenize($t, '\s+')) lt 4">

If you are not using XSLT 3.0, another approach is probably better.

Cheers,

Abel Braaksma
Exselt.net



---- Original Message ----
From: Ihe Onwuka <ihe(_dot_)onwuka(_at_)gmail(_dot_)com>
To: "xsl-list" <xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
Sent: Zat, Feb 15, 2014, 9:42 PM
Subject: [xsl] Patterns and scoped variables (or rather lack thereof)

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.

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