Re: [xsl] Creating a sequence from DSV strings

Subject: Re: [xsl] Creating a sequence from DSV strings
From: James Abley <james.abley@xxxxxxxxx>
Date: Fri, 22 Oct 2010 09:42:22 +0100
On 21 October 2010 18:27, Martin Honnen <Martin.Honnen@xxxxxx> wrote:
> James Abley wrote:
>
>> I am trying to pass in a DSV string parameter; e.g. "1234,356,6576" to
>> my stylesheet processing. The string may contain zero, one or many
>> members.
>>
>> I'm trying to create a sequence using this parameter.
>
> Isn't
> B tokenize("1234,356,6576", ",")
> all you need.
>

Yes, that occurred to me as I was driving home yesterday. Just needed
a bit of space from the problem to see the simpler option.

>> I then want to check to see whether an attribute in my source document
>> is contained within that sequence and do different processing based on
>> the result.
>>
>> I'm struggling converting the string into a sequence.
>>
>> I have these globals in my stylesheet:
>>
>> B  B  B  B <!-- CSV list of article IDs which can be linked to -->
>> B  B  B  B <xsl:param name="article_ids" as="xs:string*" select="'392795'"
/>
>>
>> B  B  B  B <xsl:variable name="article_id_list">
>> B  B  B  B  B  B <xsl:analyze-string select="$article_ids"
regex='([0-9]+)'>
>> B  B  B  B  B  B <xsl:matching-substring>
>> B  B  B  B  B  B  B  B <xsl:value-of select="regex-group(1)"/>
>> B  B  B  B  B  B </xsl:matching-substring>
>> B  B  B  B  B  B </xsl:analyze-string>
>> B  B  B  B </xsl:variable>
>
> B  B  B  B <xsl:variable name="article_id_list" as="xs:string*"
> select="tokenize($article_ids, ',')"/>
>
>> I have the following function intended to operate on the sequence.
>>
>> B  B <!--
>> B  B  B  B XPath function which returns true if the sequence contains the
>> candidate item, otherwise false.
>
> You don't need a function simply check
> B  $article_id_list = $candidate-string
>
>

Thanks, I wasn't aware of that. Less code is always better!

Cheers,

James

Current Thread