我在尝试在 XSL 样式表中包含和访问多个 XML 文档时遇到问题。我将文档节点分配为变量,然后尝试在 xsl:template 中访问它们,类似于:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" omit-xml-declaration="yes" />
<xsl:variable name="doc1" select="document('test.xml')" />
<xsl:template match="/">
<div>
<span id="id_total">
<xsl:value-of select="count($doc1//Root)"/>
</span>
</div>
</xsl:template>
</xsl:stylesheet>
使用 IE 和 Firefox 时我得到了正确的计数,但是任何 WebKit 浏览器(Safari、Chrome)给我的计数都是 0。有什么想法吗?
Chrome 有一个跨域策略防止包含本地文件。 document 函数只能在本地引用自身:
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="pitarget.xml"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml"
>
<xsl:variable name="gal" select="'howdy'"/>
<?var gal?><!--howdy-->
<?echo gal?>
<?html5 ?>
<xsl:output method="html" encoding="utf-8" version="" indent="yes" standalone="no" media-type="text/html" omit-xml-declaration="no" doctype-system="about:legacy-compat" />
<xsl:template match="xsl:stylesheet">
<xsl:apply-templates select="processing-instruction()"/>
</xsl:template>
<xsl:template match="/">
<xsl:value-of select="processing-instruction('html5')"/>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
</head>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="processing-instruction('echo')">
<xsl:value-of select="//xsl:variable/@select[../@name=current()]"/>
<xsl:value-of select="count(document('pitarget.xml')//*) - 1"/>
</xsl:template>
<xsl:template match="processing-instruction('var')">
<xsl:processing-instruction name="{.}">
<xsl:value-of select="."/>
<xsl:value-of select="./following-sibling::node()"/>
</xsl:processing-instruction>
</xsl:template>
</xsl:stylesheet>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)