If I'm reading this right, the XQuery 1.0 spec allows zero or one values for an 
attribute: http://www.w3.org/TR/xquery/#id-computedAttributes

[113]   
CompAttrConstructor
   ::=   
"attribute" (QName |
("{" Expr "}")) "{" Expr? "}"

But MarkLogic will allow me to use a computed constructor to make an attribute 
that has a sequence for its value, but it doesn't look like the sequence stays 
a sequence:

let $xml := <root>{attribute { "greeting" } { ("hi", "bye") }}</root>
return ($xml/@greeting/fn:data(.))[1]

=> hi bye


Except for class attributes in the xhtml namespace, which apparently can have a 
sequence for their value:

declare namespace xhtml = "http://www.w3.org/1999/xhtml";;
let $xml := <xhtml:div>{attribute { "class" } { ("red", "green") }}</xhtml:div>
return ($xml/@class/fn:data(.))[1]

=> red

But if the class is not in the xhtml namespace the class attribute does not 
have an sequence:

let $xml := <div>{attribute { "class" } { ("red", "green") }}</div>
return ($xml/@class/fn:data(.))[1]

=> red green


So I am guessing this is not a bug but it is intentional, and maybe works with 
way so that you can easily check for class values like this:

declare namespace xhtml = "http://www.w3.org/1999/xhtml";;
let $xml := <xhtml:div>{attribute { "class" } { ("red", "green") }}</xhtml:div>
return $xml/@class = "green"

=> true

because without the xhtml namespace the answer is different:

let $xml := <div>{attribute { "class" } { ("red", "green") }}</div>
return $xml/@class = "green"

=> false

Also it looks like a space is used as a delimiter in the class value, so:

declare namespace xhtml = "http://www.w3.org/1999/xhtml";;
let $xml := <xhtml:div>{attribute { "class" } { ("red green") }}</xhtml:div>
return ($xml/@class/fn:data(.))[1]

=> red


So am I understanding this correctly? Are there other nuances? That xhtml 
namespace can be a little tricky because of the nuances.

thanks,
Ryan


                                          
_______________________________________________
General mailing list
General@developer.marklogic.com
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to