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

时间:2021-03-22 00:26:31

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文件。如何使用此单个XML文件将其各自的节点拆分为多个单独的页面,并使用链接进行导航?有人能给我一个起点吗?

XML FILE

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>

Output:

输出:

<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 个解决方案

#1


2  

XSLT 1.0 or 2.0?

XSLT 1.0还是2.0?

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:

我担心在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>

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.)

并使用参数的不同值重复调用它(在上面的示例中,n =要使用的Color元素的编号 - 1,2,3等)

In XSLT 2.0 see this example

在XSLT 2.0中,请参阅此示例

#2


2  

xsl:result-document can be used to output multiple processed files from a single stylesheet.

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

#1


2  

XSLT 1.0 or 2.0?

XSLT 1.0还是2.0?

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:

我担心在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>

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.)

并使用参数的不同值重复调用它(在上面的示例中,n =要使用的Color元素的编号 - 1,2,3等)

In XSLT 2.0 see this example

在XSLT 2.0中,请参阅此示例

#2


2  

xsl:result-document can be used to output multiple processed files from a single stylesheet.

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