[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

FW: Calling function with text parameter

Subject: FW: Calling function with text parameter
From: Hélder Sousa <hsousa@xxxxxx>
Date: Thu, 31 Oct 2002 17:06:35 -0000
onclick function 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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.