如何使用XSLT生成多个HTML页面?

时间:2012-05-10 16:11:59

标签: xml xslt

我有这个XML文件。如何使用这个单个XML文件与每个节点分成多个单独的页面,并通过链接进行导航?有人能给我一个起点吗?

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>

2 个答案:

答案 0 :(得分:2)

xsl:result-document可用于从单个样式表输出多个已处理的文件。

答案 1 :(得分:2)

XSLT 1.0或2.0?

我担心在1.0中没有多输出关键字 - 你必须在外部做一些事情 - 例如带参数的XSLT:

<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等。)

在XSLT 2.0中,请参阅this示例