2017-03-11 19 views
0

我試圖使用XQuery提取HTML表格的單元格中的所有值。我使用的查詢,你可以在下面找到,給出以下結果使用XQuery提取HTML表格的所有行和列(以及它們的rowspans和colspans)

Warning on line 11 column 22 of queryExtractTable.xq: 
    The child axis starting at an attribute node node will never select anything 
Warning on line 11 column 63 of queryExtractTable.xq: 
    The child axis starting at an attribute node node will never select anything 
<?xml version="1.0" encoding="UTF-8"?>hello colspan rowspan 

爲什麼「孩子軸開始於一個屬性節點的節點將永遠不會選擇任何」我不明白。

我正在使用撒克遜。

下面是查詢

declare default element namespace "http://www.w3.org/1999/xhtml"; 


declare function local:analyzeTable(
$table as element(table)) 
{ 
    for $r in $table//tr 
     return 
      for $c in $r//td 
        return (normalize-space($c), string("colspan"), 
$c/@colspan//text() , string("rowspan"), $c/@rowspan//text()) 

}; 


for $t in //table 
    return 
     local:analyzeTable($t) 

<table> 
    <tr> 
     <td colspan="2">hello</td> 
    </tr> 
</table> 

回答

1

該警告是通過表達式以下等提出:

$c/@colspan//text() 

@colspan是屬性節點,和屬性節點沒有任何子節點。因此,當您要求屬性的後代text()節點時,撒克遜人會提出警告。

要訪問這些屬性的字符串值,你可以改變這些表達式:

string($c/@colspan) 

我看到你已經熟悉了string()功能,例如string("colspan");請注意雖然這裏的string()函數是無關的,並且"colspan"足以構造一個文字字符串。

欲瞭解更多關於text()string()data(),請參閱https://developer.marklogic.com/blog/text-is-a-code-smell

相關問題