xslt - 如何为以下 TEI 片段生成 XSLT 样式表?
问题描述
我想请你帮忙。我对 XSLT 完全陌生,我想知道是否有人可以向我展示以下 TEI 片段的正确 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
元素。
推荐阅读
- json - 使用 API 在 GCP 中创建存储桶的问题
- sql - SQL:将修复字符串附加到选择结果集中
- reactjs - 了解使用效果挂钩工作的异步行为
- .net - 在 System.Data.DataColumn.set_Item :字符串未被识别为有效的 DateTime
- java - Gradle 找不到本地依赖项目
- apache-kafka - 领导者选举发生时客户端重新平衡
- java - 如何修复卡在碰撞中的物体
- php - Laravel 8 急流 || 未定义变量:_instance(查看:C:\xampp\htdocs\veye-website\resources\views\vendor\jetstream\components\modal.blade.php
- marklogic - 如何从 DHS 调用丰富 API?
- region - Halcon - 验证区域是否为空