TEI-XML 字典到简单的 HTML table 使用 XSL
TEI-XML dictionary to simple HTML table using XSL
需要将 "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 table 行(即 HTML tr
元素 HTML table
) 然后根据需要设置 table
并在 tbody
中处理所有 entryFree
元素,使用模板将它们映射到 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
的模板。
至于格式化 table,这是一个 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>
in 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>
需要将 "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 table 行(即 HTML tr
元素 HTML table
) 然后根据需要设置 table
并在 tbody
中处理所有 entryFree
元素,使用模板将它们映射到 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
的模板。
至于格式化 table,这是一个 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>
in 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>