Výstup do více souborů

  • instrukce xsl:result-document umí část výstupu nasměrovat do samostatného souboru

  • jedna transformace tak může generovat velice rozsáhlé hypertextově provázané weby

Příklad 9. Generování více souborů – soubory.xsl

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="2.0">

<xsl:variable name="style">
  <style>
    body { font-family: Calibri, sans-serif; }
    h1 { text-align: center; background-color: navy; color: yellow; }
    h2 { color: navy; }
  </style>  
</xsl:variable>

<xsl:template match="/">
  <xsl:result-document href="out/index.html">
    <html>
      <head>
        <title>Program <xsl:value-of select="název"/></title>
        <xsl:copy-of select="$style"/>
      </head>
      <body>
        <h1><xsl:value-of select="/konference/název"></xsl:value-of></h1>
        <table border="1">
          <tr>
            <th>Název</th>
            <th>Přednáší</th>
          </tr>
          <xsl:for-each select="/konference/přednáška">
            <tr>
              <td>
                <a href="{generate-id(.)}.html"><xsl:value-of select="název"/></a>
              </td>
              <td><xsl:value-of select="autor/jméno"/></td>
            </tr>
          </xsl:for-each>  
        </table>
        <xsl:apply-templates select="/konference/přednáška"/>
      </body>
    </html>
  </xsl:result-document>
</xsl:template>

<xsl:template match="přednáška">
  <xsl:result-document href="out/{generate-id(.)}.html">
    <html>
      <head>
        <title><xsl:value-of select="název"/></title>
        <xsl:copy-of select="$style"/>
      </head>
      <body>
        <h1><xsl:value-of select="/konference/název"></xsl:value-of></h1>        
        <xsl:apply-templates/>
        <hr/>
        <a href="index.html">Zpět na seznam přednášek</a>
      </body>
    </html>
  </xsl:result-document>
</xsl:template>

<xsl:template match="název">
  <h2><xsl:apply-templates/></h2>
</xsl:template>

<xsl:template match="autor">
  <p>
    <i>
      <xsl:value-of select="jméno"/>
      <xsl:if test="organizace">
        (<xsl:value-of select="organizace"/>)
      </xsl:if>
    </i>
  </p>
</xsl:template>

<xsl:template match="sekce">
  <p>Sekce: <b><xsl:apply-templates/></b></p>
</xsl:template>

<xsl:template match="popis">
  <p><xsl:apply-templates/></p>
</xsl:template>
  
</xsl:stylesheet>