XSLT Xalan dyn:evaluate example
Asked Answered
J

3

2

I want yo use the EXSLT - DYN:EVALUATE in a style sheet. I have added the names pace but I don't know where the .xsl file I need to import is. I don't believe I have XALAN installed to point the import to. How would I install this? Once installed and I point it to the .xsl will it pick up the function and apply it? I am running Windows. The XSLT file is included at the top of the XML document.

Thanks

Pete

Jealousy answered 23/10, 2008 at 16:27 Comment(0)
G
6

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.

Gadolinium answered 24/10, 2008 at 5:11 Comment(1)
I'm aware this is an ancient thread, but be aware that if you use javax.xml.transform.TransformerFactory to abstract away your XSLT processor, dyn:evaluate will fail with the default TransformerFactory implementation shipped with the JDK. This is because the JDK implementation is the Xalan XSLTC compiler, not the interpreter, and although dyn:evaluate is recognized, it cannot be handled.Isodimorphism
J
0

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.

Jealousy answered 24/10, 2008 at 8:13 Comment(0)
A
0

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.

Assai answered 28/12, 2008 at 19:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.