xsl-list
[Top] [All Lists]

Re: How do you set the action attribute for an HTML form using XSLT?

2003-03-31 17:10:32
Ricardo Castillo wrote:
Hi.  I'm trying to transform XML into an HTML/JSP page.

Unfortunately, JSP is not HTML. When you rely on the XSLT processor to
serialize the result tree in HTML syntax, it's going to make conservative
decisions as to how to make abstract elements, attributes, and character data
manifest as encoded text with embedded markup. The HTML it produces is
intended to be processed by a conforming HTML user agent. A JSP engine is not
such an agent.

The serializer does know that certain HTML attributes are subject to different
kinds of formatting, but it has no way of knowing that instead of one of the
standard types of attribute values, you want to insert a completely unescaped
JSP tag.

I've followed the suggestion at 
http://www.dpawson.co.uk/xsl/sect2/N1553.html#d1670e229

using:

<xsl:attribute name="action" saxon:disable-output-escaping="yes" 
xmlns:saxon="http://icl.com/saxon";>
  <xsl:text>&lt;&#37;&#61;request.getRequestURI()&#37;&gt;</xsl:text>
</xsl:attribute>

[...]

This is what I get:

  <form method="get" action="<%25=request.getRequestURI()%25>">

And of course I'd like:

  <form method="get" action="<%=request.getRequestURI()%>">

Ordinarily that method would work, but the "action" attribute of an HTML form
element is one of those special attributes that is supposed to be a URI
reference, so the serializer, thinking it is helping you produce a proper
value, is turning "%" into "%25". This behavior is not required by the XSLT
spec except for non-ASCII characters, and IMHO it should not be happening at
all (e.g., what if you already had properly escaped such characters in your
URI?)

So I would call this a bug in Saxon. saxon:disable-output-escaping="yes"
should, IMHO, disable *all* escaping.

<xsl:attribute name="action">
  <xsl:text 
disable-output-escaping="yes">&lt;&#37;&#61;request.getRequestURI()&#37;&gt;</xsl:text>
</xsl:attribute>

That method would definitely not work because xsl:attribute discards the text
nodes that were created in its content and only uses their encapsulated text.
Escaping only happens at serialization time. The d-o-e flag indicates you'd
prefer the serializer to not escape a text node's encapsulated text upon
output, but that only applies to the serialization of the text node; it
doesn't change the node's encapsulated text at all.

Mike

-- 
  Mike J. Brown   |  http://skew.org/~mike/resume/
  Denver, CO, USA |  http://skew.org/xml/

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



<Prev in Thread] Current Thread [Next in Thread>