XSLT专业站 - 提供xslt和xml相关的资料书籍和教程  
XSLT专业站 - 提供xslt和xml相关的资料书籍和教程
网站地图  收藏本站
首页 | 热门文章 | 精彩实例 | 经典教程 | XSLT语法详解 | 资料下载 | 休闲天地 | 交流论坛
  当前位置:首页>XSLT语法详解>文章内容
XSLT 语法详解:xsl:apply-imports
来源:XSLT.org.cn 作者:XSLT专业站 发布时间:2007-10-27  
XSLT 语法详解:xsl:apply-imports
<xsl:apply-imports> 允许你对指定的结点使用重写的模板,相当于Java中的super()方法。
必须的属性:无
可选的属性:无
<xsl:apply-imports>是一个空元素。

下面是针对<xsl:apply-imports>用法的实例。

XML文件:
<?xml version="1.0"?>
<test>

  <p>This is a test XML document used by several
  of our sample stylesheets.</p>
  <question>
    <text>When completed, the Eiffel Tower was the
    tallest building in the world.</text>
    <true correct="yes">You're correct!  The Eiffel
    Tower was the world's tallest building until 1930.</true>
    <false>No, the Eiffel Tower was the world's tallest
    building for over 30 years.</false>
  </question>
  <question>
    <text>New York's Empire State Building knocked the
    Eiffel Tower from its pedestal.</text>
    <true>No, that's not correct.</true>
    <false correct="yes">Correct!  New York's Chrysler
    Building, completed in 1930, became the world's tallest.</false>
  </question>
</test>


我们要导入的XSLT样式表(imported.xsl):
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:output method="html"/>

  <xsl:template match="/">
    <html>
      <body>
        <xsl:for-each select="//text|//true|//false">
          <p>
            <xsl:apply-templates select="."/>
          </p>
        </xsl:for-each>
      </body>
    </html>
  </xsl:template>

  <xsl:template match="text">
    <xsl:text>True or False: </xsl:text><xsl:value-of select="."/>
  </xsl:template>

  <xsl:template match="true|false">
    <b><xsl:value-of select="name()"/>:</b>
    <br/>
    <xsl:value-of select="."/>
  </xsl:template>

</xsl:stylesheet>


该XSLT样式表简单地格式化了XML中的<true> 和 <false>元素。如图


下面是新的XSLT样式表,其中利用<xsl:apply-imports>在XSLT中导入其他的样式表
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>A Brief Test</title>
<style>
<!--
            p.question {font-size: 125%; font-weight: bold}
            p.right    {color: green}
            p.wrong    {color: red}
          -->
</style>
</head>
<body>
<h1>A Brief Test</h1>
<table border="1">
<tr bgcolor="lightslategray">
<td>
<p class="question">True or False: When completed, the Eiffel
Tower was the tallest building in the world.</p>
</td>
</tr>
<tr>
<td>
<p class="right">
<b>true:</b>
<br>You're correct!  The Eiffel Tower was the world's tallest
building until 1930.</p>
</td>
</tr>
<tr>
<td>
<p class="wrong">
<b>false:</b>
<br>No, the Eiffel Tower was the world's tallest building for
over 30 years.</p>
</td>
</tr>
</table>
<br>
<table border="1">
<tr bgcolor="lightslategray">
<td>
<p class="question">True or False: New York's Empire State Building
knocked the Eiffel Tower from its pedestal.</p>
</td>
</tr>
<tr>
<td>
<p class="wrong">
<b>true:</b>
<br>No, that's not correct.</p>
</td>
</tr>

<tr>
<td>
<p class="right">
<b>false:</b>
<br>Correct!  New York's Chrysler Building, completed in 1930,
became the world's tallest.</p>
</td>
</tr>
</table>
<br>
</body>
</html>


具体的页面表现为:


标题: XSLT 语法详解:xsl:apply-imports
关键字:XSLT语法 语法详解 xsl:apply-imports 实例
上一篇:xsl:sort 语法   下一篇:XSLT 语法详解: xsl:apply-templates
  XSLT语法详解热点文章
·xsl:for-each 语法
·xsl:choose, xsl:when 和 xsl:ot
·xsl:sort 语法
·XSLT 语法详解: xsl:apply-templ
·XSLT 语法详解: xsl:attribute
·XSLT 语法详解: xsl:attribute-s
·xsl:template 和 xsl:apply-temp
·xsl:value-of 语法
·xsl:if 语法
  XSLT语法详解相关文章
·xsl:sort 语法
·XSLT 语法详解: xsl:apply-templ
·xsl:choose, xsl:when 和 xsl:ot
·XSLT 语法详解: xsl:attribute
·xsl:if 语法
·XSLT 语法详解: xsl:attribute-s
·xsl:for-each 语法
·xsl:value-of 语法
·xsl:template 和 xsl:apply-temp
Copyright© 2007 xslt.org.cn All rights reserved.