简体   繁体   中英

How to generate multiple HTML pages using XSLT?

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 FILE

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

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

XSLT 1.0 or 2.0?

I am afraid that in 1.0 there is no multiple output keyword - you'll have to do something externally - eg 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>

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

In XSLT 2.0 see this example

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM