XQuery – 计算 parent 之前的兄弟姐妹
XQuery – counting parent’s preceding siblings
我希望我能够计算出 ePub 中最高 div
的前面的兄弟姐妹(作为脚注)。在通过 XSLT 传递注释之前,我需要将值传递给属性。
for $note in doc('/db/custom_jh/bukwor.xml')//tei:note[@place='bottom']
let $parent := count($note[preceding-sibling::tei:div[@n='1']])
let $update := update insert attribute att2 {$parent} into $note
return $note
尝试 $note[preceding-sibling::tei:div[@n='1']]
或 $note[ancestor-or-self::tei:div[@n='1']]
returns 只是 0
或所有 div 的总和。
如果可能,类似于 XSLT 中的 <xsl:number level="any" select="tei:div[@n='1']/>"
。
更新
用于计数的最小代码(仍然不起作用,returns 只有 6 × 1
,应该至少有一个 2
:
for $note at $count in doc('/db/custom_jh/bukwor.xml')//tei:note[@place='bottom']
let $parent := count($note[ancestor-or-self::*/tei:div[@n='1']])
return $parent
我不知道 XML 的 ePub 格式,也没有提供示例 XML,所以要求不明确,至少对我而言。但是根据标题,你可能想要这样的东西:
let $parent := count($note/parent::*/preceding-sibling::tei:div[@n='1'])
基本上从当前 $note
的 parent 元素中计算前面的兄弟 tei:div
,其中 tei:div
具有 n
属性值等于 1
.
整个例子有点糟糕。最后,我重组了整个事情。目前,我是这样做的:
let $chaps :=
(
let $countAll := count($doc//tei:note)
for $chapter at $count in $doc//tei:div[@n='1']
let $countPreceding := count($chapter/preceding::tei:div[@n='1']//tei:note[@place='bottom'])
let $params :=
<parameters>
<param name="footnoteNo" value="{$countPreceding}"/>
</parameters>
return
<entry name="OEBPS/chapter-{$count}.xhtml" type="xml">
{
transform:transform($chapter, doc("/db/custom_jh/xslt/style-web.xsl"), $params)
}
</entry>
)
count($chapter/preceding::tei:div[@n='1']//tei:note[@place='bottom'])
对我有用。 (我需要将所有脚注收集到一个文件中,并在不同文件中建立指向其索引位置的反向链接)。
我希望我能够计算出 ePub 中最高 div
的前面的兄弟姐妹(作为脚注)。在通过 XSLT 传递注释之前,我需要将值传递给属性。
for $note in doc('/db/custom_jh/bukwor.xml')//tei:note[@place='bottom']
let $parent := count($note[preceding-sibling::tei:div[@n='1']])
let $update := update insert attribute att2 {$parent} into $note
return $note
尝试 $note[preceding-sibling::tei:div[@n='1']]
或 $note[ancestor-or-self::tei:div[@n='1']]
returns 只是 0
或所有 div 的总和。
如果可能,类似于 XSLT 中的 <xsl:number level="any" select="tei:div[@n='1']/>"
。
更新
用于计数的最小代码(仍然不起作用,returns 只有 6 × 1
,应该至少有一个 2
:
for $note at $count in doc('/db/custom_jh/bukwor.xml')//tei:note[@place='bottom']
let $parent := count($note[ancestor-or-self::*/tei:div[@n='1']])
return $parent
我不知道 XML 的 ePub 格式,也没有提供示例 XML,所以要求不明确,至少对我而言。但是根据标题,你可能想要这样的东西:
let $parent := count($note/parent::*/preceding-sibling::tei:div[@n='1'])
基本上从当前 $note
的 parent 元素中计算前面的兄弟 tei:div
,其中 tei:div
具有 n
属性值等于 1
.
整个例子有点糟糕。最后,我重组了整个事情。目前,我是这样做的:
let $chaps :=
(
let $countAll := count($doc//tei:note)
for $chapter at $count in $doc//tei:div[@n='1']
let $countPreceding := count($chapter/preceding::tei:div[@n='1']//tei:note[@place='bottom'])
let $params :=
<parameters>
<param name="footnoteNo" value="{$countPreceding}"/>
</parameters>
return
<entry name="OEBPS/chapter-{$count}.xhtml" type="xml">
{
transform:transform($chapter, doc("/db/custom_jh/xslt/style-web.xsl"), $params)
}
</entry>
)
count($chapter/preceding::tei:div[@n='1']//tei:note[@place='bottom'])
对我有用。 (我需要将所有脚注收集到一个文件中,并在不同文件中建立指向其索引位置的反向链接)。