`
747017186
  • 浏览: 317359 次
社区版块
存档分类
最新评论

xslt参数的传递和接受

    博客分类:
  • xml
 
阅读更多

我们都知道在外面不能像xslt里面传递参数的,至少不能直接传过去,所以我们可以像个办法。

先看个例子:

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/" name="show_title">

<xsl:param name="testParam"><xsl:value-of select="//参数"></xsl:value-of></xsl:param>

<语料 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://shangyuan/shuju_yuliao">

<xsl:copy-of select=".//书籍/部分[@type=$testParam]/node()"></xsl:copy-of>

</语料> 

</xsl:template>

</xsl:stylesheet>

 

这个例子里面我想在传入的document里面添加一个叫参数的节点,实际上这个节点在原文档是不纯在的。我在这里只是起到传参的作用。在这里取到这个参数之后,在其他的地方用的话直接用“$param的名字”进行取值,很方便。

 

当然如果要向外输出参数,也可以写入这个xml文档,传入到外面再进行解析。很方便。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics