Xml 如何将多个xsl文件添加到一个xsl文件中
我正在尝试将头文件和nav文件添加到另一个xsl文件中Xml 如何将多个xsl文件添加到一个xsl文件中,xml,html,xslt,Xml,Html,Xslt,我正在尝试将头文件和nav文件添加到另一个xsl文件中header.xsl和nav.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:o
header.xsl
和nav.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>
初始XSLT失败,因为
xsl:import
必须是xsl:stylesheet
的子项。请注意,导入样式表实际上不会导致在该点应用该样式表中的任何模板
在第一种情况下,您需要做的是将导入的nav.xsl
与导入的header.xsl
<xsl:import href="header.xsl" />
<xsl:import href="nav.xsl" />
然后,在主XSLT中,您可以使用xsl:apply imports
,您以前的xsl:import
用于“nav.xsl”
对于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>
<?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>
<xsl:import href="header.xsl" />
<xsl:import href="nav.xsl" />
<xsl:template match="body">
<div class="container-fluid ">
...
</div>
</xsl:template>
<xsl:template match="body">
<body>
<!-- content of other element -->
<xsl:apply-imports />
<xsl:apply-templates select="footer" />
</body>
</xsl:template>
<xsl:template name="header">