大家好,快乐的一年!
再一次,我需要你在XSLT中进行转换的帮助。
我有一个包含大量pb元素的XML-TEI文件。例如:
<pb ed="bnf" id="f77.image.r"/>
我在同一个文件中也有一个链接元素:
<link id="bnf" target="http://test.com:/12148/btv1b90621925/"/>
我在xslt中的转换不仅应该将<pb>
元素转换为HTML格式:[77r],而[77r]也应该是超链接。
现在,它只做了第一件事:
<xsl:template match="pb[@ed='bnf']"><span class="pb">
<xsl:text> [</xsl:text>
<xsl:value-of select="substring-after(substring-before(@id, '.image.'), 'f')"/><xsl:value-of select="substring-after(@id, '.image.')">
</xsl:value-of>
<xsl:text></xsl:text>
<xsl:apply-templates/>
<xsl:text>] </xsl:text>
</span>
</xsl:template>
如何到达link元素并执行此操作[f77r]获取链接的值并将其与pb元素的id连接起来?每个pb应该是这样的超链接(每个pb的末尾都会改变):
http://test.com:/12148/btv1b90621925/的 f77.image.r
非常感谢你的帮助:)
祝福, 米莎
答案 0 :(得分:0)
看起来您可以在此处使用密钥,以link
属性查找id
元素。
<xsl:key name="links" match="link" use="@id" />
然后,在构造超链接的href
时,可以使用该键来获取链接的目标<a href="{key('links', @ed)/@target}{@id}">
请注意两次使用属性值模板来创建属性。你也可以写这个如果你想要
<a href="{concat(key('links', @ed)/@target, @id)}">
试试这个XSLT模板
<xsl:template match="pb[@ed='bnf']">
<span class="pb">
<a href="{concat(key('links', @ed)/@target, @id)}">
<xsl:text> [</xsl:text>
<xsl:value-of select="substring-after(substring-before(@id, '.image.'), 'f')"/><xsl:value-of select="substring-after(@id, '.image.')">
</xsl:value-of>
<xsl:apply-templates/>
<xsl:text>] </xsl:text>
</a>
</span>
</xsl:template>
这应该输出以下内容:
<span class="pb">
<a href="http://test.com:/12148/btv1b90621925/f77.image.r"> [77r] </a>
</span>