从 XML TEI 文件中提取数据

问题描述

我正在使用 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>

但似乎不是正确的语法使用。有什么建议吗?

解决方法

Cuhio8.

apply-templates 语法中有一个错字,看起来您需要将 div 与 @type='chapter' 匹配,并为后代元素应用模板 name with @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>

请告诉我它是否适合您。

最好的问候,瓦西尔

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...