如何使用XSLT生成多个HTML页面?(How to generate multiple HTML

2019-09-17 03:56发布

我有这样的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>

Answer 1:

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看到这个例子



Answer 2:

xsl:result-document可以被用来输出多个处理的文件从一个单一的样式表。



文章来源: How to generate multiple HTML pages using XSLT?
标签: xml xslt