XML/XSLT stylesheet/import — различия между версиями

Материал из Web эксперт
Перейти к: навигация, поиск
 
м (1 версия)
 
(нет различий)

Текущая версия на 08:26, 26 мая 2010

Import another xsl style sheet

File: dummy.xsl
<?xml version="1.0"?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0">
  <xsl:include href="dummya.xsl" />
</xsl:transform>
File: dummya.xsl
<?xml version="1.0"?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0">
  <xsl:import href="dummyb.xsl" />
  <xsl:import href="dummyc.xsl" />
</xsl:transform>

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



This template has higher precedence over the templates being imported

File: Data.xml
<?xml version = "1.0" encoding = "UTF-8"?>
<book isbn = "999-99999-9-X">
   <title>Russ Tick&apos;s XML Primer</title>
   <author>
      <firstName>Russ</firstName>
      <lastName>Tick</lastName>
   </author>
   <chapters>
      <frontMatter>
         <preface pages = "2" />
         <contents pages = "5" />
         <illustrations pages = "4" />
      </frontMatter>
      <chapter number = "3" pages = "44">
         Advanced XML</chapter>
      <chapter number = "2" pages = "35">
         Intermediate XML</chapter>
      <appendix number = "B" pages = "26">
         Parsers and Tools</appendix>
      <appendix number = "A" pages = "7">
         Entities</appendix>
      <chapter number = "1" pages = "28">
         XML Fundamentals</chapter>
   </chapters>
   <media type = "CD" />
</book>
File: Transform.xslt
<?xml version = "1.0" encoding = "UTF-8"?>
<xsl:stylesheet version = "1.0" 
   xmlns:xsl = "http://www.w3.org/1999/XSL/Transform">
   <xsl:import href = "style.xsl" />
   <xsl:template match = "title">
      <h2 xmlns = "http://www.w3.org/1999/xhtml">
         <xsl:value-of select = "." />
      </h2>
   </xsl:template>
</xsl:stylesheet>

File: style.xsl
<?xml version = "1.0" encoding = "UTF-8"?>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns="http://www.w3.org/1999/xhtml">
  <xsl:output method="xml" omit-xml-declaration="no"
    doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
    doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" />
  <xsl:template match="book">
    <html>
      <head>
        <title>Combining Style Sheets</title>
      </head>
      <body>
        <xsl:apply-templates />
      </body>
    </html>
  </xsl:template>
  <xsl:template match="title">
    <xsl:value-of select="." />
  </xsl:template>
  <xsl:template match="author">
    <p>
      Author:
      <xsl:value-of select="lastName" />
      ,
      <xsl:value-of select="firstName" />
    </p>
  </xsl:template>
  <xsl:template match="*|text()" />
</xsl:stylesheet>