问题描述
我正在处理诗歌,我想为每节经文提供一个自己的 ID,该 ID 将诗歌编号和诗句编号混合在一起。
标题:
<?xml version="1.0" encoding ="UTF-8" standalone ="no" ?>
<TEI xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<teiHeader>
<fileDesc>
<titleStmt>
<title n="013">13</title>
诗句:
<lg>
<l n="01"></l>
</lg>
我想为 <l>
创建一个 xml:id 属性,例如 p013-v01(诗 13,来自 n@title;第 1 节来自 n@l)。有没有办法对每一行自动执行?
这样做的目的是比较同一首诗的版本和版本。有人告诉我这样做,但说实话,我不确定这个 xml:id 属性的效用。我希望你能帮助我。谢谢!
解决方法
<xsl:template match="l">
<xsl:variable name="id-num" select="concat('p',ancestor::TEI/descendant::title/@n,'-v',./@n)"/>
<l id="{$id-num}">
<xsl:attribute name="n"><xsl:value-of select="@n"/></xsl:attribute>
<xsl:apply-templates/>
</l>
</xsl:template>
id-value 是文本字符串和两个属性值串联的结果。