我想將一個頭文件和導航文件添加到另一個xsl文件中。 header.xsl
和nav.xsl
但它不起作用。如何將多個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="header.xsl" />
<xsl:output method="html" encoding="UTF-8"
omit-xml-declaration="yes" doctype-system="about:legacy-compat" indent="no"
media-type="text/html" />
<!-- <xsl:template match="/"> <xsl:apply-templates /> </xsl:template> <xsl:template
match="/response"> <HTML dir="ltr"> <xsl:apply-templates /> </HTML> </xsl:template> -->
<xsl:template match="body">
<body>
<xsl:import href="nav.xsl" />
<!-- content of other element -->
<xsl:apply-templates select="footer" />
</body>
</xsl:template>
</xsl:stylesheet>
header.xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- header.xsl -->
<xsl:output method="html" encoding="UTF-8" indent="no"
media-type="text/html" doctype-system="about:legacy-compat" />
<xsl:template match="header">
<!-- content of header -->
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="description" content="..." />
<meta name="author" content="..." />
<meta name="robots" content="NOINDEX, NOFOLLOW" />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="expires" content="-1" />
<!-- Bootstrap -->
<link href="/assets/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet" />
<link href="/assets/bootstrap/dist/css/bootstrap-theme.min.css"
rel="stylesheet" />
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="/assets/jquery/dist/jquery.js"></script>
<!-- Include all compiled plugins (below), or include individual files
as needed -->
<script src="/assets/bootstrap/dist/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="/stylesheets/simple-sidebar.css" />
<link rel="stylesheet" type="text/css" href="/stylesheets/ccp.css" />
<link rel="icon" type="image/png" href="/images/ccp.ico" />
<!--[if IE]><link rel="shortcut icon" href="images/ccp.ico"/><![endif] --><!-- Internet Explorer -->
<script language="javascript" SRC="/javascripts/ccp.js"></script>
<title>
<xsl:value-of select="/response/header/title" />
- title
</title>
</HEAD>
</xsl:template>
</xsl:stylesheet>
nav.xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- header.xsl -->
<xsl:output method="html" encoding="UTF-8" indent="no"
media-type="text/html" doctype-system="about:legacy-compat" />
<xsl:template match="/">
<div class="container-fluid ">
<div class="logo">
</div>
<div class="row">
<div class="header">
<div class="row-fluid">
<div class="col-xs-5 col-sm-7 col-md-9">
<h2 style="padding-left: 15px !important;">
<xsl:value-of select="/response/header/title" />
</h2>
</div>
<div class="col-xs-4 col-sm-3 col-md-2 vcenter" style="text-align: right;font-size: 8pt;">
<xsl:value-of select="/response/header/user" />
|
<a>
<xsl:attribute name="href">/logout.php?csrf=<xsl:value-of
select="/response/header/token" /></xsl:attribute>
Logout
<img src="/images/page-layout/logout-button.gif" alt="Icon: Logout"
title="Logout" />
</a>
</div>
</div>
</div>
<div class="row-fluid" style="clear: both;position: relative;top: -50px;margin-left: 95px;">
<div class="col-sm-8">
<xsl:value-of select="/response/header/description" />
</div>
<div class="col-sm-4 text-right">
<a href="/landing.php">
Connectivity Compliance Portal (CCP)
<span style="font-size:7pt">v3.0</span>
</a>
</div>
</div>
</div>
</div>
<!-- Sidebar -->
<div id="sidebar-wrapper">
<ul class="sidebar-nav">
<xsl:for-each select="/response/header/nav/container">
<xsl:if test="title = admin">
<li class="sidebar-brand">
<a>
<xsl:attribute name="href"><xsl:value-of
select="link" /></xsl:attribute>
<xsl:value-of select="title" />
</a>
</li>
</xsl:if>
<xsl:for-each select="sub_modules">
<li class="menu">
<a href="#">
<xsl:value-of select="title" />
</a>
</li>
<xsl:for-each select="menuitem">
<li>
<a>
<xsl:attribute name="href"><xsl:value-of
select="link" /></xsl:attribute>
<xsl:value-of select="title" />
</a>
</li>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</ul>
</div>
<!-- /#sidebar-wrapper -->
</xsl:template>
</xsl:stylesheet>
我看不到我在這裏做錯了什麼。輸出應該是html5。
在Firefox/IE /鉻它的錯誤,火狐顯示Error loading stylesheet: Parsing an XSLT stylesheet failed.
UPDATE
我曾嘗試以下爲好,但不也是工作
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:include href="header.xsl" />
<xsl:include href="nav.xsl" />
<xsl:output method="html" encoding="UTF-8"
omit-xml-declaration="yes" doctype-system="about:legacy-compat" indent="no"
media-type="text/html" />
<!-- <xsl:template match="/"> <xsl:apply-templates /> </xsl:template> <xsl:template
match="/response"> <HTML dir="ltr"> <xsl:apply-templates /> </HTML> </xsl:template> -->
<xsl:template match="/">
<xsl:call-template name="header"/>
<xsl:call-template name="nav"/>
<!-- Page Content -->
<!-- content of other element -->
<xsl:apply-templates select="footer" />
</xsl:template>
</xsl:stylesheet>