Re: regular expression matching in <assert>

Mukul Gandhi <[email protected]>
Newsgroups gmane.text.xml.xerces-j.user
Message-ID <CABuuzNOWnPks2b8Cim7Pxr0z2ADp+U-h_VsTEdRvTidhZhkF6g@mail.gmail.com>
Hi Jim,
    Thanks for sending across the schema and XML instance documents. I
looked at the schema document you've shared.

The following fix seems to work for your problem <assert>,

<xsd:assert test="if (matches(string(@target), '.*')) then true() else
false()"  xpathDefaultNamespace="##targetNamespace"/>

i.e, we use a string() function around attribute node @target. The
'target' attribute within your schema has type annotation of
xsd:IDREFS, therefore we seem to need this workaround.

On Wed, Apr 17, 2013 at 9:06 PM, Jim Barnett <[email protected]> wrote:
> Mukul,
>   Thanks for your response.  I've attached a sample schema and test file (the schema is edited down from a much larger document, so it's structure may not make much sense.)   The problem is in the <assert> in line 74 of the schema.  (The simpler <assert> in line 73 works properly.)
>
> I suspect that you may be right about there being a namespace problem, because the <assert> in line 74 fails even if I wrap not() around it.  So both
>
> <xsd:assert test="if (matches(@target, '.*')) then true() else false()"  xpathDefaultNamespace="##targetNamespace"/>
> And
> <xsd:assert test="if not((matches(@target, '.*'))) then true() else false()"  xpathDefaultNamespace="##targetNamespace"/>
>
> both fail, which makes it look like the processor is not finding the matches() function.
>
> The 'xpathDefaultNamespace="##targetNamespace"' attribute is something I stumbled across when trying to get some other assertions to work, but I admit that I don't really understand what effects it may be having.
>
> Thank you for your help.
>
> - Jim




-- 
Regards,
Mukul Gandhi
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.