我正在使用TEI XML文件完成对一本小说的编码。我想使用XSLT提取每个章节的字符,标记为:
<name type="character" key="nameofthecharacter">Name</name>结构是这样的:
</teiHeader>
<text>
<body>
<div n='firstchapter' type='chapter'>
<head>title</head>
<p><name type="character" key="Sam">Sam</name> is a character
</p>
</div>
<div n='secondchapter' type='chapter'>
<head>title</head>
<p><name type="character" key="Elody">Elody</name> is a character
</body>
</text>
</TEI>
我尝试了基本的XSLT,如下所示:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="text"/>
<xsl:template match="/TEI/text/body/div[@type = 'book']"/>
<xsl:apply-templates select="name[@type = "character"/>
</xsl:template>
</xsl:stylesheet>
但似乎不是正确的语法。有什么建议吗?
发布于 2021-07-07 21:30:45
Cuhio8。
应用模板语法中有一个拼写错误,看起来您需要将div与@type =‘章节’相匹配,并为带有@type= 'character‘的后代元素名称应用模板。
在这种情况下,应该像这样修改XSLT代码:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="text"/>
<xsl:template match="/TEI/text/body/div[@type = 'chapter']">
<xsl:apply-templates select="descendant::name[@type = 'character']"/>
</xsl:template>
</xsl:stylesheet>
如果对你有效,请让我知道。
致以最好的问候,Vasyl
https://stackoverflow.com/questions/68270847
复制相似问题