views:

2483

answers:

3

I'm getting the following error when I try to use the JSTL XML taglib:

/server-side-transform.jsp(51,0) 
According to TLD or attribute directive in tag file,
attribute xml does not accept any expressions

I'm looking into the tlds etc, but if anyone knows what this is an can save me some time, it'd be appreciated!

If it helps, I get this error running the example code

<c:set var="xml">
  <paragraph>
    This document uses <bold>unusual</bold> markup,
    which we want to replace with <bold>HTML</bold>.
  </paragraph>
</c:set>

<c:set var="xsl">
  <?xml version="1.0"?>
  <xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

    <xsl:template match="paragraph">
      <p><xsl:apply-templates/></p>
    </xsl:template>

    <xsl:template match="bold">
      <b><xsl:value-of select="."/></b>
    </xsl:template>
  </xsl:stylesheet>

</c:set>

<x:transform xml="${xml}" xslt="${xsl}"/>

in my /server-side-transform.jsp - my taglib directives are:

<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/xml" prefix="x" %>

and I do have standard.jar and jstl.jar in /WEB-INF/lib.

+2  A: 

Your code is picking up an "incorrect" version of x-1_0.tld, probably due to classpath issues. I see for instance on my current classpath, I have one version of x-1_0.tld that ALLOWS runtime-expressions ${syntax} in this tag and one that does not. The one in standard.jar does not allow EL expressions, while the one I have in jetty does.

krosenvold
A: 

I found that the Sun documentation refers to the URI as

http://java.sun.com/jsp/jstl/xml

The tag is now being called correctly, so this was the cause of the problem; however I am getting a NullPointerException in doEndTag()... ho hum

Brabster
JSTL1.1 is <%@ taglib uri="http://java.sun.com/jsp/jstl/xml" prefix="x"%>, the other is 1.0
krosenvold
A: 

Not exactly, you should use

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%&gt;

to use JSTL 1.1.

Unfortunately the standard.jar files includes many versions of *.tld tag for eg.

  • c-1_0-rt.tld
  • c-1_0.tld
  • c.tld
  • fmt-1_0-rt.tld
  • fmt-1_0.tld
  • fmt.tld
  • fn.tld
  • permittedTaglibs.tld
  • scriptfree.tld
  • sql-1_0-rt.tld
  • sql-1_0.tld
  • sql.tld
  • x-1_0-rt.tld
  • x-1_0.tld
  • x.tld

so by using

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%&gt;

you tell the jsp to specifically use JSTL 1.1 which btw fixes the above issue, if this does not work try using

<%@ page isELIgnored="false" %>

which basically tells jsp to evaluate EL.

/srm

Sandeep More