If you really wanted to see if "facet" was one of the class names instead of 
say "facetx" then converting to string and using contains will break.

<div class="facetx foo"/>

//div[contains(@class/string(), "facet")]   ==  TRUE

wheras this should do what you want

//div[@class = "facet"]

( providing of course the xhtml schema is in scope).



-----------------------------------------------------------------------------
David Lee
Lead Engineer
MarkLogic Corporation
[email protected]
Phone: +1 812-482-5224
Cell:  +1 812-630-7622
www.marklogic.com<http://www.marklogic.com/>


From: [email protected] 
[mailto:[email protected]] On Behalf Of Jakob Fix
Sent: Wednesday, February 27, 2013 6:24 PM
To: MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] problem interpreting an XPath expression?

right, forcing the string() does the trick. thanks, that takes away another 
excuse not to write these xray tests! ;-)

cheers,
Jakob.

On Thu, Feb 28, 2013 at 12:15 AM, Michael Blakeley 
<[email protected]<mailto:[email protected]>> wrote:
Yes, or explicitly take the string value:

xdmp:describe(
  <div xmlns="http://www.w3.org/1999/xhtml";>{
  attribute class { 'foo bar' } }</div>/@class/string())
=>
"foo bar"

So //div[contains(@class/string(), "facet")] should work.

-- Mike

On 27 Feb 2013, at 14:36 , Jakob Fix 
<[email protected]<mailto:[email protected]>> wrote:

> Ah ha! So if I'd be able to pretend the XHTML is"just XML", then this 
> should/could be considered/casted as a string?
>
> cheers,
> Jakob.
>
>
> On Wed, Feb 27, 2013 at 10:37 PM, Michael Blakeley 
> <[email protected]<mailto:[email protected]>> wrote:
> It's because @class in xhtml is NMTOKENS, tokenized by whitespace. So 
> atomization yields (xs:NMTOKEN('mainPane', xs:NMTOKEN('clearfix')) rather 
> than xs:string('mainPane clearfix').
>
> xdmp:describe(
>   <div xmlns="http://www.w3.org/1999/xhtml";>{
>   attribute class { 'foo bar' } }</div>/@class/data(.))
> =>
> (xs:NMTOKEN("foo"), xs:NMTOKEN("bar"))
>
> -- Mike
>
> On 27 Feb 2013, at 13:07 , Jakob Fix 
> <[email protected]<mailto:[email protected]>> wrote:
>
> > Hi,
> >
> > I am probably daft here, but I'm getting an error for the following 
> > expression which I'm trying to apply to your typical Bootstrap-based HTML 
> > page:
> >
> > //div[contains(@class, "facet")]
> >
> > The error I'm getting is the following:
> >
> > [1.0-ml] XDMP-ARGTYPE: (err:XPTY0004) fn:contains(attribute{fn:QName("", 
> > "class")}{"mainPane clearfix"}, "facet") -- arg1 is not of type xs:string?
> >
> > This expression works elsewhere, but MarkLogic returns this error. I'm 
> > stumped ... Oh, I've upgraded to 6.0-2.3.  Thanks as ever!
> >
> > cheers,
> > Jakob.
> > _______________________________________________
> > General mailing list
> > [email protected]<mailto:[email protected]>
> > http://developer.marklogic.com/mailman/listinfo/general
>
> _______________________________________________
> General mailing list
> [email protected]<mailto:[email protected]>
> http://developer.marklogic.com/mailman/listinfo/general
>
> _______________________________________________
> General mailing list
> [email protected]<mailto:[email protected]>
> http://developer.marklogic.com/mailman/listinfo/general

_______________________________________________
General mailing list
[email protected]<mailto:[email protected]>
http://developer.marklogic.com/mailman/listinfo/general

_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to