Jump to content

Inserting functions in XSLT files


ameliabob

Recommended Posts

I am trying to get a function into an XSLT file and am having (I think) some syntax problems

<xsl:if test="SignalsDir !='' " >									<tr>                             <td>                            <input type="checkbox"  onclick='DoProcessing(<xsl:value-of select="symbol"/>)' name="able" value="yes"  />

Can I not do something like this?I am also trying to put something into an input box with code like this

		<td align="center"> <input type="text" />			<xsl:value-of select='SignalsQty'/></td>

Link to comment
Share on other sites

try this<input type="checkbox" onclick="DoProcessing({symbol})" name="able" value="yes" /><input type="text" value="{SignalsQty}" /> the curly braces are intended for this usage
For the most part it worked. That is the XSLT processor accepted it. However, when I went to the DoProcessing it took the {symbol} as a function.e.g.function DoProcessing(argument){alert("Show Argument " + argument);}<input type="checkbox" onclick="DoProcessing({symbol})" name="able" value="yes" />symbol is displayed as Test" The browser comes back with the response "Test is not defined"I didn't mean it to be defined just passed as a string.?????
Link to comment
Share on other sites

I have broken the code fragments into three pieces the part from the XSLT file, the part from the XML file and the code that puts the two together

[b]code from $fromfile[/b]<xsl:for-each select="UserData/market/contract"><td>  <input type="checkbox" onclick="SignalClicked({symbol})" name="able" value="yes"  />	</xsl:for-each>[b]code from $xformation[/b]<?xml version="1.0"?><UserData>                	<market>                                   <contract><symbol>CT8Z </symbol></contract></market></UserData>[b]transform code the echo returns to the browser[/b]$newxml = new DOMDocument;$newxml->load($fromFile);$newxsl = new DOMDocument;$newxsl->load( $xFormation);$process = new XSLTProcessor;$process->importStyleSheet($newxsl);echo $process->transformToXML($newxml);	

I don't know how to show your the raw transformation

Link to comment
Share on other sites

I don't know enough PHP to determine if your code is overwriting the function. Here is a complete page using XML data islands for both the source XML and the XSLT. If uses MSXML 6.0 but it does work by writing to the innerHTML of a div. The XSLT works fine (which was the original question) and the event fires. I'm afraid I'm can't help with the PHP code

<html>	<head>	<xml id="xmlSource">		<UserData>			<market>				<contract><symbol>CT8Z </symbol></contract>			</market>		</UserData>	</xml>	<xml id="xslStyle">		<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  version="1.0">		<xsl:output method="html" />			<xsl:template match="/">				<xsl:for-each select="//contract">					<input type="checkbox" onclick="DoProcessing('{symbol}')" name="able" value="yes" />				</xsl:for-each>			</xsl:template>		</xsl:stylesheet>	</xml>		<script type="text/javascript">	    	function loadXML()    		{				var xmlDoc   =     new ActiveXObject("Msxml2.DOMDocument.6.0")				xmlDoc.async=false;				xmlDoc.loadXML(xmlSource.xml);				var xslSource   =     new ActiveXObject("Msxml2.FreeThreadedDOMDocument.6.0")				xslSource.async=false;				xslSource.loadXML(xslStyle.xml);				xslSource.setProperty("SelectionNamespaces", "xmlns:xsl='http://www.w3.org/1999/XSL/Transform'")				var objTransformer	=	new ActiveXObject("Msxml2.XSLTemplate.6.0")				objTransformer.stylesheet = xslSource.documentElement				var objProcessor = objTransformer.createProcessor()				objProcessor.input = xmlDoc				objProcessor.transform()				//document.write(objProcessor.output)				document.getElementById("content").innerHTML = objProcessor.output			}			function DoProcessing(value)			{				alert(value)			}		</script>	</head>	<body onload="loadXML()">		<div id="content"></div>	</body></html>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...