RE: Re[2]: [xsl] multiple output

Subject: RE: Re[2]: [xsl] multiple output
From: Sabrina Fords <Sabrina.Fords@xxxxxxxxxx>
Date: Wed, 12 Dec 2001 18:39:31 -0000


<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
  xmlns:redirect="org.apache.xalan.xslt.extensions.Redirect"
  xmlns:saxon="http://icl.com/saxon";
  xmlns:xt="http://www.jclark.com/xt";
  extension-element-prefixes="redirect saxon xt">

  <xsl:output method="html"/>

  <xsl:template match="/">
    <xsl:choose>
      <xsl:when test="contains(system-property('xsl:vendor'), 'James
Clark')">
        <xsl:for-each select="/book/chapter">
          <xt:document method="xml" 
            href="chapter{position()}.html">
            <html>
              <head>
                <title><xsl:value-of select="title"/></title>
              </head>
              <body>
                <h1><xsl:value-of select="title"/></h1>
                <xsl:apply-templates select="para"/>
                <xsl:if test="not(position()=1)">
                  <p><a href="chapter{position()-1}.html">Previous</a></p>
                </xsl:if>
                <xsl:if test="not(position()=last())">
                  <p><a href="chapter{position()+1}.html">Next</a></p>
                </xsl:if>
              </body>
            </html>
          </xt:document>
        </xsl:for-each>
      </xsl:when>
      <xsl:when test="contains(system-property('xsl:vendor'), 'Apache')">
        <xsl:for-each select="/book/chapter">
          <redirect:write select="concat('chapter', position(), '.html')">
            <html>
              <head>
                <title><xsl:value-of select="title"/></title>
              </head>
              <body>
                <h1><xsl:value-of select="title"/></h1>
                <xsl:apply-templates select="para"/>
                <xsl:if test="not(position()=1)">
                  <p><a href="chapter{position()-1}.html">Previous</a></p>
                </xsl:if>
                <xsl:if test="not(position()=last())">
                  <p><a href="chapter{position()+1}.html">Next</a></p>
                </xsl:if>
              </body>
            </html>
          </redirect:write>
        </xsl:for-each>
      </xsl:when>
      <xsl:when test="contains(system-property('xsl:vendor'), 'SAXON')">
        <xsl:for-each select="/book/chapter">
          <saxon:output href="chapter{position()}.html">
            <html>
              <head>
                <title><xsl:value-of select="title"/></title>
              </head>
              <body>
                <h1><xsl:value-of select="title"/></h1>
                <xsl:apply-templates select="para"/>
                <xsl:if test="not(position()=1)">
                  <p><a href="chapter{position()-1}.html">Previous</a></p>
                </xsl:if>
                <xsl:if test="not(position()=last())">
                  <p><a href="chapter{position()+1}.html">Next</a></p>
                </xsl:if>
              </body>
            </html>
          </saxon:output>
        </xsl:for-each>
      </xsl:when>
      <xsl:otherwise>
        <html>
          <head>
            <title><xsl:value-of select="/book/title"/></title>
          </head>
          <xsl:for-each select="/book/chapter">
            <h1><xsl:value-of select="title"/></h1>
            <xsl:apply-templates select="para"/>
          </xsl:for-each>
        </html>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template match="para">
    <p><xsl:apply-templates select="*|text()"/></p>
  </xsl:template>

</xsl:stylesheet>


------------------------------------------------------------------
Sample xml
--------------------------------------------------------------------------

<?xml version="1.0"?>
<book>
  <title>XSLT</title>
  <chapter>
    <title>Getting Started</title>
    <para>If this chapter had any text, it would appear here.</para>
  </chapter>
  <chapter>
    <title>The Hello World Example</title>
    <para>If this chapter had any text, it would appear here.</para>
  </chapter>
  <chapter>
    <title>XPath</title>
    <para>If this chapter had any text, it would appear here.</para>
  </chapter>
  <chapter>
    <title>Stylesheet Basics</title>
    <para>If this chapter had any text, it would appear here.</para>
  </chapter>
  <chapter>
    <title>Branching and Control Elements</title>
    <para>If this chapter had any text, it would appear here.</para>
  </chapter>
  <chapter>
    <title>Functions</title>
    <para>If this chapter had any text, it would appear here.</para>
  </chapter>
  <chapter>
    <title>Creating Links and Cross-References</title>
    <para>If this chapter had any text, it would appear here.</para>
  </chapter>
  <chapter>
    <title>Sorting and Grouping Elements</title>
    <para>If this chapter had any text, it would appear here.</para>
  </chapter>
  <chapter>
    <title>Combining XML Documents</title>
    <para>If this chapter had any text, it would appear here.</para>
  </chapter>
</book>


e-mail and any files transmitted with it are confidential and intended
solely for the use of the individual or entity to whom they are addressed.
If you are not an intended recipient, please notify info@xxxxxxxxxx
immediately. Please note that some of our communications may contain
confidential information which it could be a criminal offence for you to
disclose or use without authority. This email is not intended nor should it
be taken to create any legal relations contractual or otherwise.

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread