我想通过XSLT从XML生成HTML 我刚刚发布了2个示例标题,但我想要动态标题
<PAP>
<headers>
<header>a1</header>
<header>a2</header>
<header>a3</header>
</headers>
<headers>
<header>b1</header>
<header>b2</header>
<header>b3</header>
</headers>
<Others>
<header>a1</header>
<header>a2</header>
<header>a3</header>
</others>
<entries>
<entry id="1">
<a1>Sample1</a1>
<a2>1000</a2>
<a3>1000</a3>
</entry>
<entry id="2">
<b1>Sample2</b1>
<b2>2000</b2>
<b3>2000</b3>
</entry>
</PAP>
第一张表
a1 a2 a3
Sample1 1000 1000
第二张表
b1 b2 b3
Sample1 1000 1000
a1 a2 a3 b1 b2 b3
Sample1 1000 1000 2000 2000 2000
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html" indent="yes"/>
<xsl:key name="k1" match="entry/*" use="concat(generate-id(..), '|', local- name())"/>
<xsl:variable name="headers" select="/REPORT/PAP/headers/header"/>
<xsl:variable name="parameter" select="/REPORT/PAP/PARAMETER"/>
<xsl:template match="PAP">
<xsl:apply-templates select="entries"/>
</xsl:template>
<xsl:template match="entries">
<html>
<head>
</head>
<body>
<table class="bed">
<thead id="columns">
<tr>
<xsl:apply-templates select="$headers" mode="header"/>
</tr>
</thead>
<tbody>
<xsl:apply-templates/>
</tbody>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="header" mode="header">
<th style="width:100px">
<xsl:value-of select="./@num"/>
</th>
</xsl:template>
<xsl:template match="entry">
<tr>
<xsl:apply-templates select="$headers">
<xsl:with-param name="entry" select="current()"/>
</xsl:apply-templates>
</tr>
</xsl:template>
<xsl:template match="header">
<xsl:param name="entry"/>
<td align="left" style="padding-left:0px;">
<xsl:value-of select="key('k1', concat(generate-id($entry), '|', .))"/>
</td>
</xsl:template>
</xsl:stylesheet>