spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / authoring / languages / xml / insidexslt / chap2 / 6 To page 1To page 2current pageTo page 4To page 5
[previous] [next]

Inside XSLT

Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs

The <xsl:include> Element

Another way to insert stylesheets inside other documents is to use the <xsl:include> element. This element enables you to include the contents of a file at a particular place in a stylesheet. This element has only one attribute:

This element is empty and has no content.

Here's an example. In this case, I'll put part of the stylesheet in planets.xsl into a new document, rules.xml. Then I can include rules.xml in planets.xsl:

Listing 2.9: Including a Stylesheet

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

  <xsl:include href="rules.xsl"/>

  <xsl:template match="/PLANETS">
    <HTML>
      <HEAD>
        <TITLE>
          The Planets Table
        </TITLE>
      </HEAD>
      <BODY>
        <H1>
          The Planets Table
        </H1>
        <TABLE BORDER="2">
          <TD>Name</TD>
          <TD>Mass</TD>
          <TD>Radius</TD>
          <TD>Day</TD>
          <xsl:apply-templates/>
        </TABLE>
      </BODY>
    </HTML>
  </xsl:template>

</xsl:stylesheet>

Here's what rules.xsl looks like. Note that it's a full XSL document with the XML declaration and the <xsl:stylesheet> element:

Listing 2.10: rules.xsl

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

  <xsl:template match="PLANET">
    <TR>
      <TD><xsl:value-of select="NAME"/></TD>
      <TD><xsl:value-of select="MASS"/></TD>
      <TD><xsl:value-of select="RADIUS"/></TD>
      <TD><xsl:value-of select="DAY"/></TD>
    </TR>
  </xsl:template>

</xsl:stylesheet>

And that's all it takes. Besides using <xsl:include> to insert stylesheets or stylesheet fragments, you can also use <xsl:import>.

Upcoming in XSLT 2.0
One of the issues that XSLT 2.0 is specifically supposed to address is that included documents are supposed to be able to use their own stylesheets. For example, if you include a document written in the XML language MathML, that included document should be able to use its own stylesheet.


home / authoring / languages / xml / insidexslt / chap2 / 6 To page 1To page 2current pageTo page 4To page 5
[previous] [next]

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint

Created: October 16, 2001
Revised: October 16, 2001


URL: http://webreference.com/authoring/languages/xml/insidexslt/chap2/6/3.html