i have a problem with XSLT…
<xsl:text> </xsl:text>
Then after generation, for some reason the resulting JSP file produces a ‘?’ instead. What’s wrong?
My recent system changes:
I changed Java5 -> Java6
Weblogic -> Weblogic12
Eclipse Ganymede -> Oracle Pack Eclipse
EDIT 1: <xsl:output method="xml"/>, encoding=UTF-8
The original XSL:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:include href="common.xsl"/>
<xsl:output method="xml"/>
...
<xsl:template name="makeLink">
<xsl:variable name="fieldtype" select="name()"/>
<xsl:variable name="currentNode"><xsl:value-of select="generate-id()"/></xsl:variable>
<xsl:variable name="appendSpace">
<xsl:for-each select="ancestor::ButtonList[position() = 1]/descendant::Button">
<xsl:if test="generate-id() = $currentNode and position() > 1">true</xsl:if>
</xsl:for-each>
</xsl:variable>
<a href="{$url}">
<xsl:attribute name="id">btn_<xsl:value-of select="Action"/></xsl:attribute>
<xsl:call-template name="populateAttributes">
<xsl:with-param name="fieldtype">
<xsl:value-of select="$fieldtype"/>
</xsl:with-param>
</xsl:call-template>
<xsl:copy-of select="@class"/>
<xsl:copy-of select="@style"/>
<xsl:text><span><span></xsl:text><xsl:value-of select="$buffer"/><xsl:text></span></span></xsl:text>
</a>
<xsl:if test="not(@omitWhiteSpace)">
<xsl:text> </xsl:text>
</xsl:if>
<xsl:if test="ReadOnly and ReadOnly != 'someReadOnlyMethod'
and ReadOnly != 'someReadyOnlyMethod'
and ReadOnly != ''">
<xsl:text></c:if></xsl:text>
</xsl:if>
</xsl:template>
....
Transformed (after XSLT), and resulting JSP page:
<%@ page contentType = "text/html;charset=GBK"%>
<%@ page isELIgnored = "false"%>
<%@ page language="java"
import=" my.controller.*, my.core.config.*, my.core.datastructure.*, my.core.error.*, my.core.util.*,
my.service.Constants, my.service.modulesvr.ModuleBean, myW.sn.*, java.util.Locale, java.util.Map"%>
<%@ taglib uri="http://www.mycompany.com/my/tags/htmltag-10" prefix="html"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%MySn mySession = (MySn) session.getValue("MySn"); QuickSearchController mb = (mySession == null) ? null : (QuickSearchController)
mySession.getModuleBean(); String sessionToken = mySession.getSessionToken(); String htmlCharSet = mySession.getEncoding();
MyUsr user = mySession.getMyUsr(); String[] result; Object o;%>
.........
<a href="#" id="btn_NEWPROP" onclick="submitForm('/xxx/xxx/NEWPROP','theForm'); return (false);" class="actionBtn"><span><span>NEW PROP</span></span></a> </c:if>
EDIT 2: it seems like if i use <xsl:text>&#160;</xsl:text> instead of <xsl:text> </xsl:text>…the problem seems to have gone away. In the JSP, it will appear as   and on the browser, it is seen as a no-break space, which is expected.
That often happens if your encoding is wrong. What encoding are you writing your output in? How are you serving up the page? Possibly you are serializing in UTF-8 but trying to display in ISO-8859-1 (or Windows-1252), or vice-versa.
Check to see if the default encoding somewhere has changed.
Just because you say
<xsl:output method="xml" encoding="UTF-8"/>doesn’t mean that the program will honor it. Is the XSLT embedded in a piece of Java? Does the Java control the streams/readers/writers?If you can save a portion of the file and dump it in HEX, you should quickly be able to find out. If you see
0xC2 0xA0then your file is indeed in UTF-8. However, if you just see0xA0alone, then you are in ISO-8859-1 or one of its close relations.It’s also possible that the page is being rendered properly, but the page is being served up with the wrong encoding. Can you look at the headers returned, perhaps by using Firebug in Firefox or in Chrome “Web Developer->Information->View Response Headers” or by using the IE debug tools.