xml - 使用 XSL 将 TEI-XML 字典转换为简单的 HTML 表
问题描述
需要把“entryFree”字放在第一列(<form>
内容留第二列),“sense”等作为第二列,每对在同一行,有边框。示例 XSL 样式表仅包含格式。
示例 XML:https ://drive.google.com/file/d/1sNAbWw5xo1pgwK2QfQwPrbZtZt8uV48T/view?usp=sharing
花式 XSL(许可证允许修改):https ://github.com/michmech/tei-dictionary.xsl
解决方案
如果要将所有entryFree
元素映射到 HTML 表格行(即 HTMLtr
中的 HTML 元素table
),则table
根据需要设置所有元素,并在一个tbody
过程中将entryFree
它们与模板映射到 a tr
:
<xsl:output method="html" doctype-system="about:legacy-doctype"/>
<xsl:template match="/">
<html>
<head>
<title>Test</title>
</head>
<body>
<h1>Table</h1>
<table>
<thead>
<tr>
<th>free entry</th>
<th>forms/senses</th>
</tr>
</thead>
<tbody>
<xsl:apply-templates select="//tei:entryFree"/>
</tbody>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="tei:entryFree">
<tr>
<td>
<xsl:value-of select="@sortKey"/>
</td>
<td>
<xsl:apply-templates/>
</td>
</tr>
</xsl:template>
tei:entryFree
您显然需要删除模板匹配。
至于格式化表格,这是一个 HTML/CSS 问题,HTML 4 https://www.w3.org/TR/html401/struct/tables.html#h-11.3.1允许例如
<table rules="all" frame="border">
<thead>
<tr>
<th>free entry</th>
<th>forms/senses</th>
</tr>
</thead>
<tbody>
<xsl:apply-templates select="//tei:entryFree"/>
</tbody>
</table>
在 HTML5 中,我认为使用 CSS 是首选:
<xsl:template match="/">
<html>
<head>
<title>Test</title>
<style>
table.dict {
border: 1px solid black;
border-collapse: collapse;
}
table.dict th, table.dict td {
border: 1px solid black;
}
</style>
</head>
<body>
<h1>Table</h1>
<table class="dict">
<thead>
<tr>
<th>free entry</th>
<th>forms/senses</th>
</tr>
</thead>
<tbody>
<xsl:apply-templates select="//tei:entryFree"/>
</tbody>
</table>
</body>
</html>
</xsl:template>
推荐阅读
- ansible - 是否有将日期字符串转换为纪元的 ansible 函数
- keras - 如何在 keras 生成器中使用 NN?
- julia - 在 Julia 中使用 ForwardDiff 时限制函数签名
- java - HTML 按钮,apache.http.client。向它发送 post 请求
- .htaccess - 如何重定向包含百分号的单个 URL?
- python - 使用并发期货时如何共享状态
- docker - 在 Gitlab 运行器中的 Docker 容器内运行测试命令时出现问题
- sql - 在 SQL Server 中同步创建临时表
- mysql - 如何在 MySQL 的列中插入值?
- python-3.x - 从 Pandas df 中选择相关的列/轴