xslt - 通过 XSL 以斜体打印
问题描述
我是语言学家,我刚刚开始了解这种语法。我想恢复name proper
,但在任何内容都ex
以斜体打印的情况下,我怎么能把它放在这张表的第一列?
这是 XML:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-model href="http://www.tei-c.org/release/xml/tei/custom/schema/relaxng/tei_all.rng" type="application/xml" schematypens="http://relaxng.org/ns/structure/1.0"?>
<?xml-model href="http://www.tei-c.org/release/xml/tei/custom/schema/relaxng/tei_all.rng" type="application/xml"
schematypens="http://purl.oclc.org/dsdl/schematron"?>
<?xml-stylesheet type="text/xsl" href="1.antroponimoscopia.xsl"?>
<TEI xmlns="http://www.tei-c.org/ns/1.0">
<teiHeader>
<fileDesc>
<titleStmt>
<title>Title</title>
</titleStmt>
<publicationStmt>
<p>Publication Information</p>
</publicationStmt>
<sourceDesc>
<p>Information about the source</p>
</sourceDesc>
</fileDesc>
</teiHeader>
<text>
<body>
<pb n="001r"/>
<div1 type="book" n="01">
<div2 type="chapter" n="000">
<cb n="a"/>
<head> Capítulo 1 </head>
<ab> Este es el texto del capítulo 1 de la columna A del folio 1r y le pongo dos
nombrecitos <name type="proper">Don alfo<ex>ns</ex>so</name> y otro nombrecillo para no perdernos doña
<name type="proper">beatriz</name>
</ab>
</div2>
<div2 type="chapter" n="001">
<cb n="b"/>
<head>Capítulo II </head>
<ab>Este es el texto del capítulo II, que se encuentra en la columba B del folio 1r.
Y vamos a poner unos nombres: don <name type="proper">al<ex>fon</ex>so</name>, doña <name type="proper">Urraca</name>
</ab>
</div2>
<pb n="001v"/>
<div2 type="chapter" n="002">
<head>Capítulo III</head>
<ab> Este es el texto del capítulo 3. Vamos a poner tres nombres:
<name type="proper">Fer<ex>nan</ex>do</name>, <name type="proper">Le<ex>tic</ex>ia</name> e <name type="proper">I<ex>s</ex>a</name>
</ab>
</div2>
</div1>
</body>
</text>
</TEI>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:tei="http://www.tei-c.org/ns/1.0">
<xsl:output method="html"/>
<xsl:template match="/">
<html lang="es">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body>
<h3 align="center">
<b>Antropónimos</b>
</h3>
<table width="750" border="1" align="center">
<tr>
<th scope="col" bgcolor="#00CCFF">
<div align="center">Nombre</div>
</th>
<th scope="col" bgcolor="#00CCFF">
<div align="center">Libro</div>
</th>
<th scope="col" bgcolor="#00CCFF">
<div align="center">Capítulo</div>
</th>
<th scope="col" bgcolor="#00CCFF">
<div align="center">Folio</div>
</th>
<th scope="col" bgcolor="#00CCFF">
<div align="center">Columna</div>
</th>
<th scope="col" bgcolor="#00CCFF">
<div align="center">Línea</div>
</th>
</tr>
<tr>
<td>
<xsl:for-each select="//tei:name[@type='proper']">
<div align="center">
<xsl:value-of select="."/>
</div>
</xsl:for-each>
</td>
<td>
<xsl:for-each select="//tei:name[@type='proper']">
<div align="center">
<xsl:value-of select="ancestor::tei:div1/@n"/>
</div>
</xsl:for-each>
</td>
<td>
<xsl:for-each select="//tei:name[@type='proper']">
<div align="center">
<xsl:value-of select="ancestor::tei:div2/@n"/>
</div>
</xsl:for-each>
</td>
<td>
<xsl:for-each select="tei:name[@type='proper']">
<div align="center">
<xsl:value-of select="preceding::tei:pb[@n][1]/@n"/>
</div>
</xsl:for-each>
</td>
<td>
<xsl:for-each select="//tei:name[@type='proper']">
<div align="center">
<xsl:value-of select="preceding::tei:cb[@n][1]/@n"/>
</div>
</xsl:for-each>
</td>
<td>
<xsl:for-each select="//tei:name[@type='proper']">
<div align="center">
<xsl:value-of select="preceding::tei:lb[@n][1]/@n"/>
</div>
</xsl:for-each>
</td>
</tr>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
谢谢!!
解决方案
一般来说,我建议为要转换的节点和要name type="proper"
使用的元素设置模板,例如
<xsl:template match="tei:name[@type = 'proper']">
<div>
<xsl:apply-templates/>
</div>
</xsl:template>
和它的ex
孩子,例如
<xsl:template match="tei:name[@type = 'proper']/tei:ex">
<em>
<xsl:apply-templates/>
</em>
</xsl:template>
请记住,XSLT 只是一种用于将 XML 转换为其他格式的编程语言,因此确定任何斜体或其他呈现的不是 XSLT,它只是用于生成您想要的输出,在您的情况下,它似乎是 HTML ,em
元素应该强调的地方。您也可以选择使用 CSS。但是,如果您想转换为 PDF,则需要使用 XSLT 来生成正确的 XSL-FO 元素和所需的属性。
一个更完整的例子是
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:tei="http://www.tei-c.org/ns/1.0"
exclude-result-prefixes="tei">
<xsl:output method="html" version="5.0" doctype-system="about:legacy-comapat"/>
<xsl:template match="/">
<html lang="es">
<head>
</head>
<body>
<h3 align="center">
<b>Antropónimos</b>
</h3>
<table width="750" border="1" align="center">
<thead>
<tr>
<th scope="col" bgcolor="#00CCFF">
<div align="center">Nombre</div>
</th>
<th scope="col" bgcolor="#00CCFF">
<div align="center">Libro</div>
</th>
<th scope="col" bgcolor="#00CCFF">
<div align="center">Capítulo</div>
</th>
<th scope="col" bgcolor="#00CCFF">
<div align="center">Folio</div>
</th>
<th scope="col" bgcolor="#00CCFF">
<div align="center">Columna</div>
</th>
<th scope="col" bgcolor="#00CCFF">
<div align="center">Línea</div>
</th>
</tr>
</thead>
<tbody>
<xsl:apply-templates select="//tei:name[@type = 'proper']"/>
</tbody>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="tei:name[@type = 'proper']">
<tr>
<td>
<xsl:apply-templates/>
</td>
<td>
<xsl:value-of select="ancestor::tei:div1/@n"/>
</td>
<td>
<xsl:value-of select="ancestor::tei:div2/@n"/>
</td>
<td>
...
</td>
<td>
...
</td>
<td>
...
</td>
</tr>
</xsl:template>
<xsl:template match="tei:name[@type = 'proper']/tei:ex">
<em>
<xsl:apply-templates/>
</em>
</xsl:template>
</xsl:stylesheet>
推荐阅读
- android - React Native Fire Base 通知监听器
- google-cloud-dataflow - 数据流:管道完成后访问价值提供者
- git - 我无法将提交推送到 github 存储库
- java - Firebase:检索嵌套对象的数据?
- powershell - 在powershell的哈希中向现有数组添加值?
- node.js - 如何使用 WebStorm 调试 NextJS React 应用程序?
- java - 在构造函数中调用静态方法有循环依赖问题?
- python - 如何从操纵循环中获取打印输出作为列表?或者,在不打印的情况下获得相同的结果?
- java - 证书错误 PKIX 路径构建失败,使用 gradle-processors-2.1.0.pom
- python - Python 通过 txt 文件搜索 url