Inside Xslt

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:

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.

Категории