AJAX/XSL: Using POST parameters in XSLT
I'm sending POST parameters to an XSLT stylesheet via AJAX.
AJAX snippet:
//param name/value is nodeid=1
xhttp.open("POST",dname,false);
xhttp.setRequestHeader("Content-type", "te开发者_如何学Cxt/plain");
xhttp.setRequestHeader("Content-length", params.length);
xhttp.setRequestHeader("Connection", "close");
xhttp.send(params);
XSL snippet
<xsl:param name="nodeid" />
<xsl:template match="/">
Hi <xsl:value-of select="$nodeid" />
</xsl:template>
"Hi" is coming back in the response, but not the nodeid. This seems pretty straightforward, so what am I missing? I've tried it running locally as well as on JRun/Coldfusion. Thoughts?
Use a processor specific API to get the nodeid
parameter before processing. Either in PHP:
$transformer = new XSLTProcessor();
$transformer->importStylesheet("foo.xsl");
$transformer->setParameter('', 'nameOfPage', $_POST['nameOfPage']);
or Coldfusion:
<cffile action="read" file="C:\CFusion\wwwroot\testdocs\simpletransform.xsl"
variable="xslDoc">
<cfset mystruct={nameOfPage=request.nameOfPage}>
<cfset transformedXML = XmlTransform(mydoc, xslDoc, mystruct)>
<cffile action="write" file="C:\CFusion\wwwroot\testdocs\transformeddoc.xml"
output=transformedXML>
or VBScript:
nameOfString = WScript.Stdin.ReadAll
or Awk:
BEGIN { FS = "=" } ; { print $2 | xargs xsltproc foo.xsl foo.xml --param nameOfPage }
References
- PI Parameters
- Setting Parameters for XSLTProcessor
- Saxon: Calling .Net
- Xalan: setParameter
- XSLTProc Man Page
- How to Write CGI Applications in Visual Basic
- Microsoft Windows 2000 Scripting Guide - Handling Input and Output
- Batch XSLT Transformation, find | xarg xsltproc
- Coldfusion: XmlTransform
精彩评论