0

A chapter-metadata.xml store in each book isbn folder(there are 100 isbn folder so there is 100 chapter-metadata.xml) which store in marklogic database server and chapter-metadata. Xml either contain data of one chapter or empty. If chapter-metadata.xml contain only one chapter information then I want to add more chapter information(my chapter infomation is common for all chapter) under chapter element with attribute and value of that chapter up to how many chapter store in book isbn folder(that I can fetch and store in a variable $chapter_sequence like ch001 ch002 ch003 ch004..) or if chapter-metadata.xml does not have any chaper information then it will create chapter element with attribute and value of chapter number and add my information, below I have put some xml structure if there is one chapter information and my information is from element keywordset

<?xml version="1.0" encoding="UTF-8" ?> 
<chaptermetadata>
<bookisbn>isbn number</bookisbn>
<booktitle>Copyright</booktitle>
<chapter id="ch001"">
<keywordset>
<keyword role="primary">context</keyword> 
<keyword role="secondary">Copyright</keyword> 
<keyword role="tertiary">subject</keyword>
</keywordset> 
</chapter>
</chaptermetadata>

I want like below:

<?xml version="1.0" encoding="UTF-8" ?> 
<chaptermetadata>
<bookisbn>isbn number</bookisbn>
<booktitle>Copyright</booktitle>
<chapter id="ch001"">
<keywordset>
<keyword role="primary">context</keyword> 
<keyword role="secondary">Copyright</keyword> 
<keyword role="tertiary">subject</keyword>
</keywordset> 
</chapter>

<chapter id="ch002"">
<keywordset>
<keyword role="primary">context</keyword> 
<keyword role="secondary">Copyright</keyword> 
<keyword role="tertiary">subject</keyword>
</keywordset> 
</chapter>
so on to last chapter which I store in veriable
</chaptermetadata>

thanks,

raj

4

1 回答 1

2

这个问题很难理解,但从http://docs.marklogic.com/xdmp:directory和一个 FLWOR 表达式开始。假设您将其放入一个函数中。我将手动介绍一些您还必须实现的辅助函数,但该函数可能看起来像这样:

declare function chaptermetadata($isbn as xs:string)
as element(chaptermetadata) {
  <chaptermetadata>
  {
    <bookisbn>{ $isbn }</bookisbn>
    <booktitle>{ title($isbn) }</booktitle>
    for $chapter in xdmp:directory(isbn-uri($isbn), 'infinity')
    return element { fn:node-name($chapter) } {
      $chapter/@*,
      $chapter/keywordset }
  }
  <chaptermetadata>
};

现在,除非您了解它所做的一切,否则此代码将无济于事,因此您可以对其进行修改以满足您的需求。这是其中一个 XQuery 用例的变体,因此您可能会发现有助于完成和理解这些用例:http: //www.w3.org/TR/xquery-use-cases/

于 2012-11-29T18:17:22.000 回答