Re: [xsl] tokenize a string with escaped spaces

Subject: Re: [xsl] tokenize a string with escaped spaces
From: "Mark Giffin m1879@xxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 4 Apr 2020 02:58:05 -0000
I found that this works for my purposes:

<xsl:analyze-string select="$outputclass" regex="\S+'[^']*'">
     <xsl:matching-substring>
         <xsl:message><xsl:value-of select="."/></xsl:message>
     </xsl:matching-substring>
</xsl:analyze-string>

Then if $attr is this:

ng-show-myModel=='Radio button 1' ng-show-myModel=='Radio button 2'

I get this back:

ng-show-myModel=='Radio button 1'
ng-show-myModel=='Radio button 2'


On 4/3/2020 6:17 PM, Mark Giffin m1879@xxxxxxxxxxxxx wrote:
> Thanks Michael. The double quotes " in the regex give errors in this 
> context:
>
> <xsl:analyze-string select="$attr" regex="\S*('[^']*')?("[^"]*")?">
>
> Should those be single quotes instead? Or should I put the regex in a 
> variable?
>
> On 4/3/2020 4:38 PM, Michael Kay mike@xxxxxxxxxxxx wrote:
>> Try using xsl:analyze-string with a regex of
>>
>> \S*('[^']*')?("[^"]*")?
>>
>> I've had to guess at your specification from your single example, but 
>> you should be able to adapt it if the spec is different.
>>
>> You could also extend the regex to pick up the keyword (before '=') 
>> and value (after '=') as captured substrings:
>>
>> (\S+)=(\S+|('[^']*')|("[^"]*"))
>>
>> and then regex-group(1) gives you the keyword, and regex-group(2) the 
>> value.
>>
>> Michael Kay
>> Saxonica
>>
>>> On 4 Apr 2020, at 00:17, Mark Giffin m1879@xxxxxxxxxxxxx 
>>> <mailto:m1879@xxxxxxxxxxxxx> 
>>> <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx 
>>> <mailto:xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>> wrote:
>>>
>>> I am tokenizing an XML attribute that has info I need in it. Example:
>>>
>>> myattr="ng-model=mymodel ng-show-mymodel=='Radio button 1'"
>>>
>>> So I want to tokenize into these two values:
>>>
>>> ng-model=mymodel
>>> ng-show='Radio button 1'
>>>
>>> Using white space like tokenize($attr, '\s') gives me this, not what 
>>> I want:
>>>
>>> ng-model=mymodel
>>> ng-show='Radio
>>> button
>>> 1'
>>>
>>> Do you have a suggestion on how to do this? Doesn't have to use 
>>> tokenize().
>>>
>>> Thanks,
>>> Mark
>>>
>>
>> XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
>> EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/805141> 
>> (by email)
>
> XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
> EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/805141> 
> (by email <>)

Current Thread