我正在尝试呈现这个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>作为我学习过程的一部分,我已经详细说明了这些内容。感谢马丁·洪宁和迈利扬!
以下是整个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都被复制了--结肠左侧的信息是正确的,但是在结肠的右侧,所有的$names都被复制了。阿格!
发布于 2017-10-30 18:39:54
我不完全确定你想要的到底是什么输出,但我就是这么理解的。假设您有一个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>解决办法是马丁·霍宁对你的问题的评论。
如果您希望您的输出是这样的:
<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表达式中,您不必经过所有节点才能获得所需的后代。如果路径是明确的,则使用// axis说明符,因为这样查询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-11-12 15:56:50
成功!经过大量的尝试和错误,这是我想出来的:
{
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>
}它为每个$respStmt返回一个列表项,其中包含$resp和$names,以逗号分隔。我觉得自己很有成就。谢谢大家的帮助!
https://stackoverflow.com/questions/47002731
复制相似问题