gpt4 book ai didi

xml - 使用浏览器转换XML时,是否可以通过URL向XSLT传递参数?

转载 作者:数据小太阳 更新时间:2023-10-29 01:39:44 26 4
gpt4 key购买 nike

当使用浏览器转换 XML(Google Chrome 或 IE7)时,是否可以通过 URL 将参数传递给 XSLT 样式表?

例子:

data.xml

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="sample.xsl"?>
<root>
<document type="resume">
<author>John Doe</author>
</document>
<document type="novella">
<author>Jane Doe</author>
</document>
</root>

示例.xsl

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">

<xsl:output method="html" />
<xsl:template match="/">
<xsl:param name="doctype" />
<html>
<head>
<title>List of <xsl:value-of select="$doctype" /></title>
</head>
<body>
<xsl:for-each select="//document[@type = $doctype]">
<p><xsl:value-of select="author" /></p>
</xsl:for-each>
</body>
</html>
</<xsl:stylesheet>

最佳答案

不幸的是,不能——您不能仅在客户端将参数传递给 XSLT。Web 浏览器从 XML 中获取处理指令;并直接使用 XSLT 对其进行转换。


可以通过查询字符串 URL 传递值,然后使用 JavaScript 动态读取它们。然而,这些不能用于 XSLT(XPath 表达式)——因为浏览器已经转换了 XML/XSLT。它们只能在呈现的 HTML 输出中使用。

关于xml - 使用浏览器转换XML时,是否可以通过URL向XSLT传递参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65926/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com