0

我正在尝试在此 TEI 标头中呈现 $respStmt 条目:

<TEI xmlns="http://www.tei-c.org/ns/1.0" xml:id="reeve-prog">
<teiHeader>
    <fileDesc>
        <titleStmt>
            <title type="statusBar">The Progress of Romance</title>
            <author>
                <person xml:id="CR" sex="F" href="http://en.wikipedia.org/wiki/Clara_Reeve">
                    <forename>Clara</forename>
                    <surname>Reeve</surname>
                    <born when="1729">1729</born>
                    <died when="1807-12-03">3 December 1807</died>
                    <occupation>Writer</occupation>
                    <occupation>Novelist</occupation>
                    <trait type="Marital Status">Unmarried</trait>
                    <nationality>English</nationality>
                </person>
            </author>
            <respStmt>
                <resp>Transcription and correction</resp>
                <name>Elizabeth Ricketts</name>
                <name>Tonya Howe</name>
            </respStmt>
            <respStmt>
                <resp>Correction, editorial commentary, and markup</resp>
                <name>Incomplete</name>
            </respStmt>
        </titleStmt>
     </filedesc>
   </teiHeader>
</TEI>

在如下所示的列表中:

<li class="list-unstyled">Transcription and correction: Elizabeth Ricketts, Tonya Howe</li>
<li class="list-unstyled">Correctionm editorial commentary, and markup: Incomplete</li>

我已将此代码添加到一个更大的函数中,它适用于多个 $name 项目,但我遇到了一个与多个 $resp 项目有关的基数问题:

for $resp in $header
                return
                <li class="list-unstyled">
                    {concat($titleStmt/tei:respStmt/tei:resp, ': ' , string-join($titleStmt/tei:respStmt/tei:name, ', '))                    }
                </li>

作为学习过程的一部分,我已经详细说明了 concat 中的元素。非常感谢 Martin Honnen 和 milijan!

这是整个 XQL 文件——我知道它不漂亮:https ://gist.github.com/tonyahowe/9ec27e9261116bdb11b0cfc2cecc5ea7

更新: 进步!不过,现在我得到了一种奇怪的重复。使用此代码:

{
                let $respStmt := $header//tei:respStmt
                for $resps in $respStmt
                return
                <li class="list-unstyled">
                    {concat($resps, ': ' , string-join($names, ', '))                    }
                </li>
            }

我得到以下结果:

Transcription and correctionElizabeth RickettsTonya Howe: Elizabeth Ricketts, Tonya Howe, Incomplete
Correction, editorial commentary, and markupIncomplete: Elizabeth Ricketts, Tonya Howe, Incomplete

看起来 $resp 基数问题已经解决了,但是现在每个 $respStmt 中的每个 $name 都被重复了——冒号左侧的信息是正确的,但是冒号右侧的所有 $名称正在被复制。精氨酸!

4

2 回答 2

0

成功!经过大量的试验和错误,这就是我想出的:

{ 
 for $respStmt in $respStmts
 let $resp := $respStmt/tei:resp
 let $name := $respStmt/tei:name
 return
 <li class="list-unstyled">
   {$resp} by {string-join($name, ', ')}
 </li>
}

它为每个包含 $resp 和 $names 的 $respStmt 返回一个列表项,以逗号分隔。我觉得很有成就感。谢谢大家,你们的帮助!

于 2017-11-12T15:56:50.153 回答
0

我不确定您要寻找的输出到底是什么,但这就是我的理解。假设您有一个 XML 文档 (contributors.xml):

<document>
<respStmt>
  <resp>Transcription, editorial commentary, and markup</resp>
  <name>students of X Y University</name>
  <name>First Specific Contributor</name>
  <name>Second Specific Contributor</name>
  <name>Third Specific Contributor</name>
</respStmt>
<respStmt>
  <resp>Editorial review</resp>
  <name>Reviewer Name</name>
  <name>Reviewer2 Name</name>
</respStmt>
<respStmt>
  <resp>Graphic design</resp>
  <name>Designer Name</name>
</respStmt>
</document>

如果你希望你的输出是这样的:

<li class="list-unstyled">Transcription, editorial commentary, and markup: students of X Y University, First Specific Contributor, Second Specific Contributor, Third Specific Contributor</li>
<li class="list-unstyled">Editorial review: Reviewer Name, Reviewer2 Name</li>
<li class="list-unstyled">Graphic design: Designer Name</li>

你可以像这样使用 xquery 脚本:

let $document := doc('contributors.xml')/*

for $resp-stmt in $document/respStmt
   return
   <li class="list-unstyled">
   {
       concat($resp-stmt/resp, ': ' , string-join($resp-stmt/name, ', '))

   }
   </li>

解决方案在 Martin Honnen 对您的问题的评论中。

如果你希望你的输出是这样的:

<li class="list-unstyled">Transcription, editorial commentary, and markup: students of X Y University, First Specific Contributor, Second Specific Contributor, and Third Specific Contributor</li>
<li class="list-unstyled">Editorial review: Reviewer Name and Reviewer2 Name</li>
<li class="list-unstyled">Graphic design: Designer Name</li>

你可以使用这个 xquery 脚本:

let $document := doc('contributors.xml')/*
for $resp-stmt in $document/respStmt
let $name := $resp-stmt/name
let $name-count := count($name)
   return
   <li class="list-unstyled">
   {concat($resp-stmt/resp, ': ')}
   {
        if ($name-count le 2)
        then string-join($name, ' and ')
        else
            concat(
                string-join($name[position() = (1 to last() - 1)] , ', '),
                ', and ',
                $name[last()])
   }
   </li>

解决方案在您提供的代码中。

要使此 xquery 代码可操作,您必须定义适当的名称空间并在适当的地方使用它们。

更新: 这个自包含示例中的脚本,其中contributors.xml 作为您提供的输入文件,应该为您提供您想要实现的目标:

declare namespace tei = 'http://www.tei-c.org/ns/1.0';    
let $document := doc('contributors.xml')/*

for $resp-stmt in $document//tei:respStmt
return
<li class="list-unstyled">
    {concat($resp-stmt/tei:resp, ': ' , string-join($resp-stmt/tei:name, ', '))}
</li>

在您的 *.xql 文件中,我相信存在一个问题,因为您没有定义 $resp 变量,因为它应该被定义。您实际上是在说 $resp 是 $header。尝试这个:

for $resp in $header//tei:respStmt
return
<li class="list-unstyled">
   {concat($header//tei:resp, ': ' , string-join($header//tei:name, ', '))}
</li>

此外,在您的 XPath 表达式中,您不必遍历所有节点来获得所需的后代。当路径明确时使用 // 轴说明符,因为这样查询 eXist-db 会更有效。

更新 2: 在您的新更新中,您使用的$names变量与上下文无关,这就是您获得这些结果的原因。我已经在之前的更新中为您提供了解决方案,但是您可以将其复制并粘贴到您的 tei2html.xql 脚本中,它应该可以工作:

{
for $respStmt in $header//tei:respStmt
return
<li class="list-unstyled">
{concat($respStmt/tei:resp, ': ' , string-join($respStmt/tei:name, ', '))}
</li>
}
于 2017-10-30T18:39:54.823 回答