replace() problem

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

replace() problem

Jim Logan-3
The spec leads me to believe the following example should print "test --", but it instead prints "test -bogon-".
<xxforms:variable
    name="test"
    select="replace('bogon', '.*/(asserted|inferred)/([^/]+)/.*', '$1')" />
<xforms:output value="concat('test -', $test, '-')" />

Can anyone explain this behavior? Is it a bug?


I was originally trying to pull the number "42" out of a URI such as the following:
http://localhost:8008/asserted/42/root/www.modeldriven.org/2008/ArchitectureOntology/Samples/SampleVersions.owl
Is there a better way?


Also, how can I cause a single or double quote to print "bogon" or 'bogon' rather than -bogon-? I've tried escaping with a backslash, but it doesn't work.

Thanks,
-Jim



--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: replace() problem

fl.schmitt(ops-users)
hi Jim,

> The spec <http://www.w3.org/TR/xquery-operators/#func-replace> leads me to
> believe the following example should print "test --", but it instead prints
> "test -bogon-".
>
> <xxforms:variable name="test" select="replace('bogon',
> '.*/(asserted|inferred)/([^/]+)/.*', '$1')" /> <xforms:output
> value="concat('test -', $test, '-')" />
>
> Can anyone explain this behavior? Is it a bug?

"The function returns the xs:string that is obtained by replacing each
non-overlapping substring of $input that matches the given $pattern with an
occurrence of the $replacement string."

In your case, the function returns the input string without a replace, because
the pattern doesn't match the input string. So, for every substring of bogon,
the replacement is empty.

> Also, how can I cause a single or double quote to print "bogon" or 'bogon'
> rather than -bogon-? I've tried escaping with a backslash, but it doesn't
> work.

That's true, \" or \' isn't a valid single character escape. You could try to
use a category esacape / block escape [1] or a character reference [2].

HTH
florian

[1] http://www.w3.org/TR/xmlschema-2/#regexs
[2] http://www.w3.org/TR/2000/WD-xml-2e-20000814#dt-charref



--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: Re: replace() problem

Erik Bruchez
Administrator
In XPath 2.0, used here, you escape single quotes by doubling them,  
e.g. ' -> ''. E.g.:

   value="concat('''', foobar, '''')"

-Erik

On Jun 8, 2008, at 8:51 AM, Florian Schmitt wrote:

> hi Jim,
>
>> The spec <http://www.w3.org/TR/xquery-operators/#func-replace>  
>> leads me to
>> believe the following example should print "test --", but it  
>> instead prints
>> "test -bogon-".
>> <xxforms:variable name="test" select="replace('bogon',
>> '.*/(asserted|inferred)/([^/]+)/.*', '$1')" /> <xforms:output
>> value="concat('test -', $test, '-')" />
>> Can anyone explain this behavior? Is it a bug?
>
> "The function returns the xs:string that is obtained by replacing each
> non-overlapping substring of $input that matches the given $pattern  
> with an
> occurrence of the $replacement string."
>
> In your case, the function returns the input string without a  
> replace, because
> the pattern doesn't match the input string. So, for every substring  
> of bogon,
> the replacement is empty.
>
>> Also, how can I cause a single or double quote to print "bogon" or  
>> 'bogon'
>> rather than -bogon-? I've tried escaping with a backslash, but it  
>> doesn't
>> work.
>
> That's true, \" or \' isn't a valid single character escape. You  
> could try to use a category esacape / block escape [1] or a  
> character reference [2].
>
> HTH
> florian
>
> [1] http://www.w3.org/TR/xmlschema-2/#regexs
> [2] http://www.w3.org/TR/2000/WD-xml-2e-20000814#dt-charref
>
>
> --
> You receive this message as a subscriber of the [hidden email]  
> mailing list.
> To unsubscribe: mailto:[hidden email]
> For general help: mailto:[hidden email]?subject=help
> OW2 mailing lists service home page: http://www.ow2.org/wws
--
Orbeon Forms - Web Forms for the Enterprise Done the Right Way
http://www.orbeon.com/



--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: Re: replace() problem

Jim Logan-3
In reply to this post by fl.schmitt(ops-users)
Florian Schmitt wrote:

> hi Jim,
>
>> The spec <http://www.w3.org/TR/xquery-operators/#func-replace> leads
>> me to
>> believe the following example should print "test --", but it instead
>> prints
>> "test -bogon-".
>>
>> <xxforms:variable name="test" select="replace('bogon',
>> '.*/(asserted|inferred)/([^/]+)/.*', '$1')" /> <xforms:output
>> value="concat('test -', $test, '-')" />
>>
>> Can anyone explain this behavior? Is it a bug?
>
> "The function returns the xs:string that is obtained by replacing each
> non-overlapping substring of $input that matches the given $pattern
> with an
> occurrence of the $replacement string."
>
> In your case, the function returns the input string without a replace,
> because
> the pattern doesn't match the input string. So, for every substring of
> bogon,
> the replacement is empty.
Florian,

I see what I misunderstood now. I thought the function would match on
the first ".*", capture nothing into $2, and use the empty $2 as the result.

Thanks,
-Jim



--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws