Setting Parameters - XSLT: Extensible Stylesheet Language Transformations 编辑
Setting Parameters
While running transformations using precoded .xsl and .xml files is quite useful, configuring the .xsl file from JavaScript may be even more useful. For example, JavaScript and XSLT could be used to sort XML data and then display it. The sorting would have to alternate between ascending and descending sorting.
XSLT provides the xsl:param
element, which is a child of the xsl:stylesheet
element. XSLTProcessor
provides three JavaScript methods to interact with these parameters: XSLTProcessor.setParameter()
, XSLTProcessor.getParameter()
and XSLTProcessor.removeParameter()
. They all take as the first argument the namespace URI of the xsl:param
(Usually the param will fall in the default namespace, so passing in null
will suffice.) The local name of the xsl:param
is the second argument. setParameter requires a third argument - namely the value to which the parameter will be set.
Figure 7 : Parameters
/* XSLT:
<xsl:param name="myOrder" />
*/
// JavaScript:
var sortVal = xsltProcessor.getParameter(null, "myOrder");
if (sortVal == "" || sortVal == "descending")
xsltProcessor.setParameter(null, "myOrder", "ascending");
else
xsltProcessor.setParameter(null, "myOrder", "descending");
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论