Hi Peter,

An empty class value does appear to be invalid according to the xhtml schema:

xquery version "1.0-ml";

let $x :=
<table xmlns="http://www.w3.org/1999/xhtml";>
    <tr class=""><td>xxx</td></tr>
    <tr class="ms-alternating"><td>aaa</td></tr>
    <tr class=""><td>xxx</td></tr>
    <tr class="ms-alternating"><td>bbb</td></tr>
    <tr class=""><td>xxx</td></tr>
</table>
return
validate { $x }
=> 1.0-ml] XDMP-VALIDATEBADTYPE: (err:XQDY0027) validate { $x } -- Invalid node 
type: @class lexical value "" invalid for expected type #xs:NMTOKENS at 
/*:table/*:tr[1]/@class using schema "xhtml1.1.xsd"

The only thing I can think of is to hack the text, something like:

xquery version "1.0-ml";
let $x :=
<table xmlns="http://www.w3.org/1999/xhtml";>
    <tr class=""><td>xxx</td></tr>
    <tr class="ms-alternating"><td>aaa</td></tr>
    <tr class=""><td>xxx</td></tr>
    <tr class="ms-alternating"><td>bbb</td></tr>
    <tr class=""><td>xxx</td></tr>
</table>
return
xdmp:unquote(fn:replace(xdmp:quote($x), 'class=""', 'class="ms-alternating"'))

-Danny

From: [email protected] 
[mailto:[email protected]] On Behalf Of Peter Lindes
Sent: Friday, September 04, 2009 7:27 AM
To: [email protected]
Cc: Stewart Shelline
Subject: [MarkLogic Dev General] Problem with empty class in XHTML

Here is a test case for the issue I'm looking at:

xquery version "1.0-ml";
declare namespace xh = "http://www.w3.org/1999/xhtml";;

let $test :=
<table xmlns="http://www.w3.org/1999/xhtml";>
    <tr class=""><td>xxx</td></tr>
    <tr class="ms-alternating"><td>aaa</td></tr>
    <tr class=""><td>xxx</td></tr>
    <tr class="ms-alternating"><td>bbb</td></tr>
    <tr class=""><td>xxx</td></tr>
</table>

let $result := <result>{$test/xh:tr}</result>

let $new-test :=
    <table>
    {
    for $r in $test//xh:tr
    let $row := <tr class="{ $r/@class }">{ $r/node() }</tr>
    return $row
    }
    </table>

let $new-result := 
<new-result>{$new-test/t...@class!="ms-alternating"]}</new-result>

return <results>{$result, $new-result}</results>

  As shown above, this query works.  It returns all the rows in the <result> 
element, and only the rows with an empty class attribute in the <new-result> 
element.  The test data is a simplified piece of a file I got from the web and 
cleaned up with tidy().

  What I would like to do is be able to apply the [...@class!="ms-alternating"] 
selector to the original $test variable, but if I try this I get an error 
saying: [1.0-ml] XDMP-LEXVAL: xs:NMTOKEN("") -- Invalid lexical value "".  The 
best I can figure out is that the xhtml namespace defines a class attribute to 
have an xs:NMTOKEN, and therefore trying to operate on an attribute that says 
'class=""' fails.  It seems like either there should be some way to process 
this data or that tidy() should strip out any empty class attributes.

  Any suggestions?

  Peter



NOTICE: This email message is for the sole use of the intended recipient(s) and 
may contain confidential and privileged information. Any unauthorized review, 
use, disclosure or distribution is prohibited. If you are not the intended 
recipient, please contact the sender by reply email and destroy all copies of 
the original message.

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

Reply via email to