XSLT Xalan dyn:evaluate example

旧城冷巷雨未停 提交于 2019-12-06 12:13:13

Xalan has the EXSL dyn:evaluate function built-in, you don't need to import anything in order to use it. You just need to declare the namespace. I'll give a small example:

input.xml:

<root>
<foo>I am foo</foo>    
<bar>I am bar</bar>    
</root>

dyn_evaluate.xsl:

<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:dyn="http://exslt.org/dynamic"
    extension-element-prefixes="dyn">

  <xsl:param name="path"/>

  <xsl:output method="text"/>

  <xsl:template match="/">
    <xsl:value-of select="dyn:evaluate($path)"/>
  </xsl:template>

</xsl:stylesheet>

Running

xalan.exe -p path '/root/foo' input.xml dyn_evaluate.xsl

gives

I am foo

Running

xalan.exe -p path '/root/bar' input.xml dyn_evaluate.xsl

gives

I am bar

Hope this helps.

How would you call this from a JSP page? The JSP serves up the XML and currently attaches the style sheet to the XML page and servers the result.

You can't, because if you'll serve the client with XML page with attached stylesheet, this wouldn't work. Browsers don't support exslt.

However, if you do XSLT processing on server (with xalan) you can get it to work, but I don't understand how you combine xslt with jsp.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!