xsl-list
[Top] [All Lists]

RE: Calling function with text parameter

2002-10-31 16:37:09
There is no way within the XSLT 1.0 standard to force the serializer to
output apostrophe as ' rather than ', but there might be a way in
your chosen product (which you don't name).

Do browsers really treat ' and ' differently? I'm appalled.

Michael Kay
Software AG
home: Michael(_dot_)H(_dot_)Kay(_at_)ntlworld(_dot_)com
work: Michael(_dot_)Kay(_at_)softwareag(_dot_)com 

-----Original Message-----
From: owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com 
[mailto:owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com] On Behalf Of 
Hélder Sousa
Sent: 31 October 2002 17:07
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: FW: [xsl] Calling function with text parameter


Hi ppl.
I have a problem with my xsl... in the "this line" comment, 
i'm trying to set the value of  "onClick" attribute, that is 
a javascript function with a text parameter, but in my html 
page it appears without the apostrophes ...<tr align="center" 
onClick="alert(&apos;hello&apos;)">...
This isn't valid for javascript. The correct result must be 
...<tr align="center" onClick="alert('hello')">...

in my servlet, i'm using the next method to make the parse

import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamSource;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.DocumentResult;
import org.dom4j.io.DocumentSource;
import org.dom4j.io.SAXReader;

public String getHTML(String xslfile)
{
try{
TransformerFactory factory = 
TransformerFactory.newInstance(); Transformer transformer = 
factory.newTransformer( new StreamSource( xslfile ) ); 
DocumentSource source = new DocumentSource( document ); 
DocumentResult result = new DocumentResult(); 
transformer.transform( source, result );

// return the transformed document
Document transformedDoc = result.getDocument();
String html = transformedDoc.asXML();
return html;
}
catch (TransformerException e){
return "<html><body><h1>Error</h1>" + e.getMessage() + 
"</body></html>"; } }

Here is the xml and xls

people.xml
<?xml version="1.0" encoding="UTF-8"?>
<people>
    <woman name="ana">
    <woman name="joana">
    <woman name="rute">
</people>


people.xsl
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
    version="1.0"
    xmlns:xalan="http://xml.apache.org/xslt";>
    <xsl:output method="html"/>
    <xsl:template match="/">
        <xsl:for-each select=".//people">
            <xsl:element name="table">
               <xsl:attribute name="width">95%</xsl:attribute>
               <xsl:attribute name="cellspacing">0</xsl:attribute>
               <xsl:attribute name="class">tableBorder</xsl:attribute>
               <xsl:for-each select="woman">
                   <xsl:element name="tr">
                      <xsl:attribute 
name="align">center</xsl:attribute>                           
          
<!--this line-->      <xsl:attribute 
name="onClick">alert('hello');</xsl:attribute>
                      <xsl:element name="td">
                            <xsl:value-of select="@name"/>
                      </xsl:element>
                   </xsl:element>
               </xsl:for-each>
            </xsl:element>
        </xsl:for-each>
        </xsl:template>
</xsl:transform> 

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



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



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