几天以来,我尝试w[@type='verb']
在字符串中添加指向子字符串的链接。我工作的一个TEI-XML
泥板的音译,从而elements
和@type
中<w>
包含的<l>
并不总是以相同的顺序。
XSLT
3.0 版:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:template match="/">
<xsl:apply-templates select="//div1"/>
</xsl:template>
<xsl:template match="//div1">
<!-- additional content before <ul> -->
<ul>
<li>
<xsl:for-each select="descendant-or-self::lg/l[@n]">
<xsl:variable name="verb1" select="w[@type='verb']"/>
<xsl:variable name="href1" select="w[@type='verb']/@lemmaRef"/>
<xsl:variable name="single-l" select="w[@type='coo'] | w[@type='noun'] | w[@type='verb'] | w[@type='num'] | w[@type='adv'] | w[@type='adj'] | g | name"/>
<xsl:value-of select="$single-l"/>
<sup><xsl:value-of select="./@n"/></sup>
</xsl:for-each>
</li>
</ul>
</xsl:template>
我需要lemmaRef
为每个w[@type='verb']
.
的样品TEI
除去I -@xml:id
从element
以外l
:对于此示例
<lg>
<l n="4b-5a" xml:id="ktu1-3_ii_l4b-5a">
<w type="coo">w</w><space/>
<w type="verb" lemmaRef="uga/verb.xsl#qry"><damage degree="medium" facs="definir"><supplied resp="KTU">t</supplied></damage>qry</w>
<g>.</g>
<w type="noun" lemmaRef="uga/noun.xsl#ġlm">ġlmm</w>
<lb/><w>b</w><space/>
<w type="noun" lemmaRef="uga/noun.xsl#št">št</w>
<g>.</g>
<w type="noun" lemmaRef="uga/noun.xsl#ġr">ġr</w>
<g>.</g>
</l>
</lg>
我需要显示:
<ul>
<li>w <a href="uga/verb.xml#qry">tqry</a> . ġlmm št . ġr .<sup>4b-5a</sup></li>
</ul>
“tqry”是包含在<l>
.
我该怎么做XSLT
才能显示<a href="{$href1}"><xsl:value-of select="$verb1"/>
. 我试过replace
的$single-l
或定义先前的新变量XSLT
的代码,但它不工作。我也试过,key
但我想我仍然有一个理解的问题......
在此先感谢您的友好建议。
我认为您不应该尝试构建一个字符串然后在那里插入标记,似乎应该可以简单地处理子元素然后匹配 将lg/l[@n]/w[@type = 'verb']
其转换为 HTML 超链接:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="3.0">
<xsl:output method="html" indent="yes" html-version="5"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<html>
<head>
<title>Example</title>
</head>
<xsl:apply-templates/>
</html>
</xsl:template>
<xsl:template match="div">
<section>
<ul>
<xsl:apply-templates select=".//lg/l[@n]"/>
</ul>
</section>
</xsl:template>
<xsl:template match="lg/l[@n]">
<li>
<xsl:apply-templates/>
<sup>
<xsl:value-of select="@n"/>
</sup>
</li>
</xsl:template>
<xsl:template match="lg/l[@n]/w[@type = 'verb']">
<a href="{@lemmaRef}">
<xsl:apply-templates/>
</a>
</xsl:template>
<xsl:template match="space">
<xsl:text> </xsl:text>
</xsl:template>
</xsl:stylesheet>
这目前并不能完全产生想要的结果,但是
<li>w <a href="uga/verb.xsl#qry">tqry</a>.ġlmmb št.ġr.<sup>4b-5a</sup></li>
取而代之的是,如果您不需要或不想要某个元素的内容,您可以为其添加一个空模板,这样它就不会产生任何输出(例如<xsl:template match="lg/l[@n]/w[not(@type)]"/>
)。
我不确定是否也缺少重要的空格以及插入它的规则是什么,您可能需要对此进行解释。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句