The xsl:document Element: Generating Multiple Output Documents

The <xsl:document> Element: Generating Multiple Output Documents

The XSLT 1.1 working draft introduced a new element, <xsl:document> , to support multiple output documents, and its likely this element will be added to XSLT 2.0. It has the following attributes:

  • href (mandatory). Indicates where the new document should be placed. Set to an absolute or relative URI, without a fragment identifier.

  • method (optional). Sets the output method used to create the result document. Set to xml, html, text, or a QName that is not an NCName.

  • version (optional). Sets the version of the output document. Set to an NMTOKEN.

  • encoding (optional). Sets the encoding of the output document. Set to a string.

  • omit-xml-declaration (optional). Set to yes or no to omit the XML declaration or not.

  • cdata-section-elements (optional). Sets the names of those elements whose content you want output as CDATA sections. Set to a whitespace-separated list of QNames.

  • doctype-public (optional). Specifies the public identifier to be used in the <!DOCTYPE> declaration in the output. Set to a string value.

  • doctype-system (optional). Specifies the system identifier to be used in the <!DOCTYPE> declaration in the output. Set to a string value.

  • encoding (optional). Sets the character encoding. Set to a string value.

  • indent (optional). Specifies whether the output should be indented to show its nesting structure. Set to yes or no.

  • media-type (optional). Sets the MIME type of the output. Set to a string value.

  • standalone (optional). Specifies whether a standalone declaration should be included in the output and sets its value if so. Set to yes or no.

This element contains a template body.

In the following example, based on a simplified stylesheet, I create two frames in an HTML document, as well as the two HTML documents that are to be displayed in those frames , frame1.html and frame2.html. I create the first frame and the document that is to appear in it, frame1.html, this way, using <xsl:document> (note that here, Im setting the version attribute to 1.1 because were using a feature that is only a part of the XSLT 1.1 working draft, but 1.1 will probably not be a legal version value in the long run; if <xsl:document> is part of XSLT 2.0, you should set the version to 2.0):

 <HTML xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xsl::version="1.1">      <HEAD>          <TITLE>              Two Frames          </TITLE>      </HEAD>      <FRAMESET cols="50%, 50%">          <FRAME src="frame1.html"/>          <xsl:document href="frame1.html">              <HTML>                  <HEAD>                      <TITLE>                          Frame 1                      </TITLE>                  </HEAD>                  <BODY>                      <H1>This is frame 1.</H1>                  </BODY>              </HTML>          </xsl:document>          .          .          . 

Then I can create the second frame and the document that is to appear in that frame, frame2.html, as follows :

Listing 6.10 Using <xsl:document>
 <HTML xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xsl::version="1.1">      <HEAD>          <TITLE>              Two Frames          </TITLE>      </HEAD>      <FRAMESET cols="50%, 50%">          <FRAME src="frame1.html"/>          <xsl:document href="frame1.html">              <HTML>                  <HEAD>                      <TITLE>                          Frame 1                      </TITLE>                  </HEAD>                  <BODY>                      <H1>This is frame 1.</H1>                  </BODY>              </HTML>          </xsl:document>        <FRAME src="frame2.html"/>        <xsl:document href="frame2.html">            <HTML>                <HEAD>                    <TITLE>                        Frame 2                    </TITLE>                </HEAD>                <BODY>                    <H1>This is frame 2.</H1>                </BODY>            </HTML>        </xsl:document>    </FRAMESET>  </HTML> 

An XSLT 1.1-Only Example

Note that this is an XSLT 1.1 working draft-only example. No publicly -available XSLT processors (that I know of) handle the <xsl:document> element yet.



Inside XSLT
Inside Xslt
ISBN: B0031W8M4K
EAN: N/A
Year: 2005
Pages: 196

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net