Jump to content

Javascript in XSL


shiwudao

Recommended Posts

Hi all, I have a question as following:Requirement: read value(string) from XML file and write it to a HTML , and add a link to the string. The link point to a CGI program with the string as the parameter.I wrote XSL file as following:<?xml version="1.0" encoding="ISO-8859-1"?><xsl:stylesheet version="1.0"xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="/">...... <script language="javascript"> <![CDATA[ var infoname = ']]><xsl:value-of select="SOMETHING"/><![CDATA['; document.write("<a href=\"display?"+ infoname +"\" target=\"_blank\">" + infoname + "</a>"); ]]> </script>[/color]......It works fine in IE, but in Mozilla it failed because in "var inoname" statement, the section "CDATA" wa changed into new line after transformed to HTML.The HTML code should be var infoname = 'XXXX';but in Mozilla, the HTML looks like var infoname = 'XXXX';Can you tell me how to fix the problem or any better solution of the requirement?Thanks a lot!

Link to comment
Share on other sites

Why don't you include all of this stuff in the pure output? I mean, why do you need a script for that?Just write

<a href="display?{SOMETHING}" target="_blank"><xsl:value-of select="SOMETHING"/></a>

Link to comment
Share on other sites

Thank you very much.>

>Why don't you include all of this stuff in the pure output? I mean, why do you need a script for that?Because I did't know can use ?{SOMETHING}! It's XSLT? I'm a fish of XSLT! :) Thanks again!>Just write>
<a href="display?{SOMETHING}" target="_blank"><xsl:value-of select="SOMETHING"/></a>

Link to comment
Share on other sites

It's called "attribute value template" or AVT in short. Every attribute's value in the output or part of it can have parenthesis, which enclose an XPath expression. The value from that expression is outputted as a string and that's it. XSLT elements' attributes which return a string in the output can also use AVT. Such examples include <xsl:attribute> (another way with which you could do your thing here) and <xsl:element>.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...