XML教程
XQuery教程
XSLT教程
XPath教程

XSLT <xsl: import>

XSLT <xsl: import>元素

XSLT <xsl: import>元素用于将一个样式表的内容导入到另一个样式表。导入样式表的优先级高于导入的样式表。
<xsl:import href = "uri"> 
</xsl:import>

参数说明

href: 用于提供要导入的xslt样式表的路径。

XSLT <xsl: import>元素示例

让我们以创建一个<employee>元素列表为例,该元素的属性为" id",其子元素为" ,<lastname>,<nickname>和<salary>遍历每个员工。在此示例中,我们创建了两个xsl样式表,其中employee_import.xsl样式表导入employee.xsl,而employee.xml链接到employee_import.xsl。
Employee.xml
<?xml version = "1.0"?>
<?xml-stylesheet type = "text/xsl" href = "employee_import.xsl"?> 
<class> 
   <employee id = "001">
      <firstname>Aryan</firstname> 
      <lastname>Gupta</lastname> 
      <nickname>Raju</nickname> 
      <salary>30000</salary>
   </employee> 
   <employee id = "024"> 
      <firstname>Sara</firstname> 
      <lastname>Khan</lastname> 
      <nickname>Zoya</nickname> 
      <salary>25000</salary>
   </employee> 
   <employee id = "056"> 
      <firstname>Peter</firstname> 
      <lastname>Symon</lastname> 
      <nickname>John</nickname> 
      <salary>10000</salary> 
   </employee> 
</class>
Employee.xsl
<?xml version = "1.0" encoding = "UTF-8"?> 
<xsl:stylesheet version = "1.0" 
   xmlns:xsl = "http://www.w3.org/1999/XSL/Transform">    
   <xsl:template match = "/"> 
      <html> 
         <body>
            <h2>Employee</h2> 
            <table border = "1"> 
               <tr bgcolor = "pink"> 
                  <th>ID</th> 
                  <th>First Name</th> 
                  <th>Last Name</th> 
                  <th>Nick Name</th> 
                  <th>Salary</th> 
               </tr>
     
               <xsl:for-each select = "class/employee"> 
     
                  <tr> 
                     <td><xsl:value-of select = "@id"/></td> 
                     <td><xsl:value-of select = "firstname"/></td> 
                     <td><xsl:value-of select = "lastname"/></td> 
                     <td><xsl:value-of select = "nickname"/></td> 
                     <td><xsl:value-of select = "salary"/></td> 
                  </tr> 
               </xsl:for-each> 
            </table> 
         </body> 
      </html> 
   </xsl:template>  
</xsl:stylesheet>
Employee_import.xsl:
<?xml version = "1.0" encoding = "UTF-8"?> 
<xsl:stylesheet version = "1.0" 
   xmlns:xsl = "http://www.w3.org/1999/XSL/Transform">  
   <xsl:import href = "employee.xsl"/>  
   <xsl:template match = "/"> 
      <xsl:apply-imports/> 
   </xsl:template>  
</xsl:stylesheet>
输出:
XSLT Xsl导入元素1
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4