简体   繁体   English

渲染转换其他元素(XSLT,XQL和eXist-db)中的XML元素

[英]Rendering transforming XML elements inside other elements (XSLT, XQL and eXist-db)

I am trying to render a title page in xml, which I'm doing through an eXist-db app. 我正在尝试在xml中呈现标题页,我正在通过eXist-db应用程序进行。 Here is the relevant xml: 这是相关的xml:

 <front> <titlePage> <titlePart> <lb>THE</lb> <lb>ADVENTURES</lb> <lb>OF</lb> <lb>Roderick Random.</lb> <lb><epigraph xml:lang="la"> <cit> <quote xml:lang="la" link="http://www.perseus.tufts.edu/hopper/text?doc=Perseus%3Atext%3A1999.02.0062" title="Satires 2.5.8: 'But birth and virtue, unless [attended] with substance, is viler than seaweed.'"> <l>Et genus &amp; virtus, nisi cum re, vilior alga est.</l> </quote> <bibl> <author ref="HOR" link="http://en.wikipedia.org/wiki/Horace" title="Quintus Horatius Flaccus, Roman lyric poet of the 1st century BCE">HOR.</author> </bibl> </cit> </epigraph> </lb> <lb>IN TWO VOLUMES.</lb> <lb>VOL. I.</lb> <lb>THE TENTH EDITION.</lb> <hr/> <lb><name type="place">LONDON:</name></lb> <lb>Printed for W. STRACHAN, J. RIVINGTON, R. BALDWIN, HAWES CLARKE, AND COLLINS, W. JOHNSTON, T. CASLON, B. LAW, J. JOHNSON AND Co, W. AND J. RICHARDSON, T. BECKETT, and P.. DeHONDT,</lb> <lb><date title="1775">MDCCLXXV.</date></lb> </titlePart> </titlePage> <pb n="titlepage" facs="smollett.png"/> </front> 

Graphically at this point, all I want is every <lb> on a separate line. 在图形上,此时,我想要的是在单独的一行上的每个<lb> I also want the <epigraph> s to appear wherever they do within the existing logic of the title page--that is, inline with the existing <lb> s. 我还希望<epigraph>在标题页的现有逻辑中出现在任何地方 - 也就是说,与现有的<lb>内联。 This screenshot should help make it clear: screenshot of flawed rendered page 此屏幕截图应该有助于说明: 有缺陷的呈现页面的屏幕截图

Here are the relevant .xql bits with the xsl transformations. 以下是带有xsl转换的相关.xql位。 If you want to see all of the .xql, you can see that here (again, apologies for the true inelegance throughout): https://gist.github.com/tonyahowe/c55167e13ae22139f94080289cb88f47 : 如果你想看到所有的.xql,你可以在这里看到(再次,为整个真正的不优雅道歉): https ://gist.github.com/tonyahowe/c55167e13ae22139f94080289cb88f47:

 declare function tei2:tei2html($nodes as node()*) { for $node in $nodes return typeswitch ($node) case text() return $node case element(tei:TEI) return tei2:tei2html($node/*) case element(tei:teiHeader) return tei2:header($node) case element(tei:frontTitle) return <h3>{ tei2:tei2html($node/node()) }</h3> case element(tei:lb) return <br>{ tei2:tei2html($node/node()) }</br> case element(tei:l) return <l>{ tei2:tei2html($node/node()) }</l> case element(tei:i) return <i>{ tei2:tei2html($node/node()) }</i> case element(tei:pb) return <span style="color:lightgray">[end page {tei2:tei2html($node/@n)}]{ tei2:tei2html($node/node()) }</span> case element(tei:footer) return <hr>{ tei2:tei2html($node/node()) }</hr> case element(tei:front) return tei2:front($node) case element(tei:rs) return tei2:link($node) case element(tei:quote) return tei2:link($node) case element(tei:note) return tei2:note($node) case element(tei:footnote) return tei2:footnote($node) case element(tei:p) return <p xmlns="http://www.w3.org/1999/xhtml" id="{tei2:get-id($node)}">{ tei2:tei2html($node/node()) }</p> (: THIS IS WHERE THE ANCHORS ARE INSERTED! :) case element(exist:match) return <mark xmlns="http://www.w3.org/1999/xhtml">{ $node/node() }</mark> case element() return tei2:tei2html($node/node()) default return $node/string() (: what would this catch? comment node in the xml? :) }; declare function tei2:link($node as element()) { if ($node/@link ne '' and $node/@link castable as xs:anyURI) then <a href="{$node/@link}" data-toggle="tooltip" title="{$node/@title}">{ tei2:tei2html( $node/node() ) }</a> else tei2:tei2html( $node/node() ) }; declare function tei2:note($node as element()) { <span style="color:black" href="{$node/@link}" data-toggle="tooltip" title="{$node/@title}"> { tei2:tei2html ( $node/node() ) }</span> }; -------------------------- cut declare function tei2:front($front as element (tei:front)) { let $titlePage := $front//tei:titlePage let $titlePart := $front//tei:titlePart let $epigraph := $front//tei:epigraph let $note := $front//tei:note let $argument := $front//tei:argument let $quote := $front//tei:quote let $bibl := $front//tei:bibl let $author := $front//tei:author return <div xmlns="http://www.w3.org/1999/xhtml" class="main-text-frontmatter"> { for $lb in $titlePage return $titlePage//tei:lb } { console:log($epigraph), for $cit in $epigraph return <blockquote> { <a href="{$quote/@link}" data-toggle="tooltip" title="{$quote/@title}">{$quote/tei:l}</a> }<br/> -- { <a href="{$author/@link}" data-toggle="tooltip" title="{$author/@title}">{$author/text()}</a> } </blockquote> } </div> }; 

Typically in TEI, the lb element is an empty, milestone element, so it only appears as: <lb/> . 通常在TEI中, lb元素是一个空的里程碑元素,因此它只显示为: <lb/> (See the TEI Guidelines on the lb element. It marks the place where a line break occurs, rather than surrounding the entire content of a line, as you have used it in the TEI here. (参见关于lb元素的TEI指南。它标记了换行的位置,而不是围绕一行的整个内容,就像你在TEI中使用它一样。

In the same way, HTML's <br/> element is an empty element. 同样,HTML的<br/>元素是一个空元素。 So your typeswitch for this element can turn into case element(tei:lb) return <br/> . 所以你的这个元素的开关可以变成case element(tei:lb) return <br/>

Adjusting your TEI markup to this <lb/> form, and adjusting your typeswitch to ourput HTML <br/> elements, may get you on the path to a solution. 将TEI标记调整为此<lb/>表单,并将类型切换调整为输出HTML <br/>元素,可以帮助您找到解决方案的途径。

I don't see where you are transforming the lb elements into HTML: 我没有看到你在哪里将lb元素转换为HTML:

for $lb in $titlePage
return 
    $titlePage//tei:lb

This will just dump out the TEI XML, which will be invalid HTML. 这只会转储TEI XML,这将是无效的HTML。

It looks like the tei2:tei2html function will render <lb> s correctly in HTML, but it will also render the <epigraph> s you want to exclude. 看起来tei2:tei2html函数会在HTML中正确呈现<lb> ,但它也会呈现您想要排除的<epigraph> If your XML is very predictable and similar to your example, you could exclude the <lb> s containing an epigraph using a predicate: 如果您的XML非常可预测且与您的示例类似,则可以使用谓词排除包含epigraph<lb>

$titlePage//tei:lb[not(tei:epigraph)]

But that is fairly brittle and will also exclude <lb> s that contain <epigraph> s mixed with any text nodes you may want to preserve. 但这是相当脆弱的,并且还会排除包含<epigraph><lb> s与您可能想要保留的任何文本节点的混合。 In that case, you can recursively process the elements to remove them: 在这种情况下,您可以递归处理元素以删除它们:

declare function local:remove-epigraph(
  $node as node()
) as node()*
{
  typeswitch ($node)
  case element(tei:epigraph) return ()
  case element() return element { node-name($node) } {
    for $n in $node/node()
    return local:remove-epigraph($node)
  }
  default return $node
};

...

$titlePage//tei:lb/local:remove-epigraph(.)

Update: 更新:

If you DO want to render the epigraph element inline, then simply use the tei2:tei2html function to render them: 如果想使epigraph元素内联,则只需使用tei2:tei2html功能,使它们:

$titlePage//tei:lb/tei2:tei2html(.)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM