如何为以下 TEI 片段生成 XSLT 样式表?
How do I generate a XSLT stylesheet for the following TEI snipet?
我想向你寻求帮助。我是 XSLT 的新手,我想知道是否有人可以向我展示以下 TEI-snipet 的正确 XSLT 样式表:
<div>
<head>Weitere Aufzählungen</head>
<list rend="numbered">
<item n="1">A</item>
<item n="2">B</item>
<item n="3">C<list rend="numbered">
<item n="3.1">a</item>
<item n="3.2">b</item>
</list>
</item>
</list>
</div>
输出应类似于 HTML-文档中的内容:
1. A
2. B
3. C
3.1 a
3.2 b
非常感谢你帮助我:)
如果您想要文本输出,下面带有 <xsl:output method="text" />
的样式表就可以了。它通过计算项目祖先节点来区分缩进级别,并在级别 0 上添加额外的 .
。
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" indent="yes" />
<xsl:variable name="newLine" select="'
'" />
<xsl:template match="text()" />
<xsl:template match="/div/list">
<xsl:apply-templates select="item" />
</xsl:template>
<xsl:template match="item">
<xsl:for-each select="ancestor::item"><xsl:text> </xsl:text></xsl:for-each>
<xsl:value-of select="@n" />
<xsl:if test="not(ancestor::item)"><xsl:text>.</xsl:text></xsl:if>
<xsl:value-of select="concat(' ',text(),$newLine)" />
<xsl:apply-templates select="list" />
</xsl:template>
</xsl:stylesheet>
输出为:
1. A
2. B
3. C
3.1 a
3.2 b
顺便说一句,您可能需要为 TEI 命名空间添加适当的命名空间声明到 xsl:stylesheet
元素。
我想向你寻求帮助。我是 XSLT 的新手,我想知道是否有人可以向我展示以下 TEI-snipet 的正确 XSLT 样式表:
<div>
<head>Weitere Aufzählungen</head>
<list rend="numbered">
<item n="1">A</item>
<item n="2">B</item>
<item n="3">C<list rend="numbered">
<item n="3.1">a</item>
<item n="3.2">b</item>
</list>
</item>
</list>
</div>
输出应类似于 HTML-文档中的内容:
1. A
2. B
3. C
3.1 a
3.2 b
非常感谢你帮助我:)
如果您想要文本输出,下面带有 <xsl:output method="text" />
的样式表就可以了。它通过计算项目祖先节点来区分缩进级别,并在级别 0 上添加额外的 .
。
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" indent="yes" />
<xsl:variable name="newLine" select="'
'" />
<xsl:template match="text()" />
<xsl:template match="/div/list">
<xsl:apply-templates select="item" />
</xsl:template>
<xsl:template match="item">
<xsl:for-each select="ancestor::item"><xsl:text> </xsl:text></xsl:for-each>
<xsl:value-of select="@n" />
<xsl:if test="not(ancestor::item)"><xsl:text>.</xsl:text></xsl:if>
<xsl:value-of select="concat(' ',text(),$newLine)" />
<xsl:apply-templates select="list" />
</xsl:template>
</xsl:stylesheet>
输出为:
1. A
2. B
3. C
3.1 a
3.2 b
顺便说一句,您可能需要为 TEI 命名空间添加适当的命名空间声明到 xsl:stylesheet
元素。