2012-12-06 68 views
0

如何在MarkLogic中爲特定屬性執行節點替換?例如象下面這樣:特定屬性節點替換

<chapters> 
<title id="primary">first primary content</title> 
<title id="primary">second primary content</title> 
<title id="secondary">this is amy middle content</title> 
<title id="terciary">this is amy last content</title> 
</chapters> 

我要象下面這樣:

<chapters> 
<title id="primary">third primary content</title> 
<title id="secondary">this is amy middle content</title> 
<title id="terciary">this is amy last content</title> 
</chapters> 

我的意思是想存儲在包含類似bleow數據MarkLogic數據庫服務器A.xml文件:

<chaptermetadata> 
<chapters> 
<title id="primary">first content</title> 
<title id="primary">second content</title> 
<title id="secondary">This is middle content</title> 
<title id="terciary">This is last content</title> 
</chapters> 
<chapters> 
<title id="primary">fouth content</title> 
<title id="primary">fifth content</title> 
<title id="primary">sixth content</title> 
<title id="secondary">This is new content</title> 
<title id="terciary">This is old content</title> 
</chapters> 
<chaptermetadata> 

現在,我想要替換所有章節中包含屬性@id='primary'的所有元素title中的節點,如下所示:

<chaptermetadata> 
<chapters> 
<title id="primary">common content</title> 
<title id="secondary">This is middle content</title> 
<title id="terciary">This is last content</title> 
</chapters> 
<chapters> 
<title id="primary">common content</title> 
<title id="secondary">This is new content</title> 
<title id="terciary">This is old content</title> 
</chapters> 
<chaptermetadata> 
+1

鑑於兩個代碼塊之間的差異,很難理解您要求的轉換 –

回答

0

如果您剛開始使用XQuery和MarkLogic,http://developer.marklogic.com/learn/technical-overviewhttp://developer.marklogic.com/learn可能會有所幫助。

修改元素和屬性的最佳方法取決於您尚未提供的上下文。我想第一個問題是「如何按屬性選擇節點?」一個簡單的XPath就可以做到這一點。對於數據庫中的所有章節:

/chapters/title[@id eq $id] 

...或相對於元素的最初選擇的序列(章)*

$chapters/title[@id eq $id] 

如果這是一個數據庫文件,你可以把它從那裏與http://docs.marklogic.com/xdmp:node-replacehttp://docs.marklogic.com/xdmp:node-delete功能。如果節點只在內存中,請參閱http://docs.marklogic.com/guide/app-dev/typeswitch以獲取有關使用XQuery類型切換或XSLT的指導和示例。在http://developer.marklogic.com/blog/tired-of-typeswitch有更多的例子,並比較typeswitch和XSLT。