如何使用 XSLT 生成多个 HTML 页面? [英] How to generate multiple HTML pages using XSLT?
问题描述
我有这个 XML 文件.我如何使用这个单一的 XML 文件将每个页面分成多个单独的页面,并通过链接浏览它?有人可以给我一个起点吗?
I have this XML file. How can I use this single XML file to split into multiple individual pages with each of their respective node and navigate through it with links? Can someone give me a starting point?
XML 文件
<Colors>
<Color>
<description>
<p>This page is red.</p>
</description>
</Color>
<Color>
<description>
<p>This page is blue.</p>
</description>
</Color>
<Color>
<description>
<p>This page is green.</p>
</description>
</Color>
<Colors>
输出:
<html>
<head></head>
<body>
This page is red.
</body>
</html>
<html>
<head></head>
<body>
This page is blue.
</body>
</html>
<html>
<head></head>
<body>
This page is green.
</body>
</html>
推荐答案
XSLT 1.0 还是 2.0?
XSLT 1.0 or 2.0?
恐怕在 1.0 中没有多个输出关键字——你必须在外部做一些事情——例如带有参数的 XSLT:
I am afraid that in 1.0 there is no multiple output keyword - you'll have to do something externally - e.g. an XSLT with a parameter:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes" method="html" />
<xsl:param name="n" select="1"/>
<xsl:template match="Color">
<xsl:value-of select="."/>
</xsl:template>
<xsl:template match="/Colors">
<html>
<head></head>
<body>
<xsl:apply-templates select="Color[$n]"/>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
并使用不同的参数值重复调用它(在上面的示例中 n
= 要使用的 Color
元素的编号 - 1、2、3 等.)
and calling it repeatedly with different values for the parameter (in the example above n
= the number of the Color
element to use - 1, 2, 3 etc.)
在 XSLT 2.0 中,请参阅这个示例
In XSLT 2.0 see this example
这篇关于如何使用 XSLT 生成多个 HTML 页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!