【发布时间】:2014-06-16 21:34:00
【问题描述】:
我按照this post from StackOverflow 的说明生成了一个每行包含 2 个单元格的 HTML 表格
但我想将我的数据分布在一个 HTML 表格中,每行三个单元格。我在帖子的 XSLT 样式表中更改了 sibling 的数字和 position 的计算,但它似乎不起作用。
这是我的 XML 源代码:
<?xml version="1.0" encoding="UTF-8"?>
<report>
<frontmatter>
<title>Relatório da 4ª Sessão Intercalar</title>
<subtitle>Projecto Integrado de Engenharia de Linguagens</subtitle>
<authors>
<author>
<name>Marina Mac</name>
<nident>pg999</nident>
<email>pg999@minho.pt</email>
<url>https://www.linkedin.com</url>
<affil>Universidade do Minho</affil>
<photo>source/img/authors/marina.png</photo>
</author>
<author>
<name>Nuno Vie</name>
<nident>pg998</nident>
<email>pg998@minho.pt</email>
<url>https://www.linkedin.com</url>
<photo>source/img/authors/nuno.jpg</photo>
<affil>Universidade do Minho</affil>
</author>
<author>
<name>Damien Va</name>
<nident>pg997</nident>
<photo>source/img/authors/damien.jpg</photo>
<url>https://www.linkedin.com</url>
<email>pg997@minho.pt</email>
<affil>Universidade do Minho</affil>
</author>
<author>
<name>Tiago Mach</name>
<nident>pg996</nident>
<email>pg996@minho.pt</email>
<url>https://www.linkedin.com</url>
<affil>Universidade do Minho</affil>
<photo>source/img/authors/marina.png</photo>
</author>
<author>
<name>Manuel Vie</name>
<nident>pg995</nident>
<email>pg995@minho.pt</email>
<url>https://www.linkedin.com</url>
<photo>source/img/authors/nuno.jpg</photo>
<affil>Universidade do Minho</affil>
</author>
<author>
<name>Damien Vim</name>
<nident>pg994</nident>
<photo>source/img/authors/damien.jpg</photo>
<url>https://www.linkedin.com</url>
<email>pg994@alunos.uminho.pt</email>
<affil>Universidade do Minho</affil>
</author>
</authors>
</frontmatter>
</report>
这是我的 XSLT 代码,它不符合我的要求:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs" version="2.0">
<xsl:output indent="yes"/>
<xsl:template match="/report">
<html>
<head>
<meta charset="utf-8"/>
<title><xsl:value-of select="frontmatter/title"/></title>
</head>
<body>
<xsl:apply-templates select="frontmatter"/>
</body>
</html>
</xsl:template>
<xsl:template match="frontmatter" >
<table width="100%">
<tr align="center">
<td>
<h1><xsl:value-of select="title"/></h1>
</td>
</tr>
<xsl:if test="subtitle != '' ">
<tr align="center">
<td>
<xsl:value-of select="subtitle"/>
</td>
</tr>
</xsl:if>
</table>
<hr width="90%"/>
<h2>Autores</h2>
<table width="90%" align="center">
<xsl:apply-templates select="authors/author[position() mod 2 = 1]"/>
</table>
</xsl:template>
<xsl:template match="authors/author">
<tr>
<xsl:for-each select=". | following-sibling::author[1]" >
<td>
<p><xsl:value-of select="name"></xsl:value-of></p>
</td>
</xsl:for-each>
<xsl:if test="not(following-sibling::author)">
<td/>
<td/>
</xsl:if>
</tr>
</xsl:template>
</xsl:stylesheet>
如何修复我的样式表,使其生成每行包含 3 个单元格的 HTML 表格?
【问题讨论】:
-
您需要包含您的源 XML。没有它就不可能提出任何建议。你想要什么也不是很清楚。最好在 HTML 代码中显示您的预期结果。
-
好的,我编辑了我的问题并放入了源 XML。 :)
-
询问代码的问题必须表明对所解决问题的最低理解。