javascript - using xsl:stream of XSLT 2.1 -
i have javascript converts applies xsl xml. need use xslt 2.1 in order use feature xsl:stream.
now script follows :
main(); function main() { if ( wscript.arguments.length != 3 ) { wscript.echo("usage: runtransform.js <xslfilename> <xmlfilename> <outputfilename>"); wscript.quit(); } var xslfilename = wscript.arguments.item(0); var xmlfilename = wscript.arguments.item(1); var outputfilename = wscript.arguments.item(2); var doc = loaddom(xmlfilename); var xsl = loaddom(xslfilename); var str = doc.transformnode(xsl); var ado = new activexobject("adodb.stream"); ado.open(); ado.position = 0; ado.charset = "utf-8"; ado.writetext(str); ado.savetofile(outputfilename, 2) } function loaddom(file) { var dom; try { dom = makedom(null); dom.load(file); } catch (e) { alert("error" + e.description); } return dom; } function makedom(progid) { if (progid == null) { progid = "msxml2.domdocument.4.0"; } var dom; try { wscript.echo("progid dom 4"); dom = new activexobject(progid); dom.async = false; dom.validateonparse = false; //dom.resolveexternals = false; } catch (e) { alert("makedom error :" + e.description); } return dom; } function alert(str) { wscript.echo(str); }
the sample xml trying follows :
<?xml version="1.0" encoding="iso-8859-1"?> <!-- edited xmlspy® --> <transactions> <transaction value="12.51"/> <transaction value="3.99"/> </transactions>
the xsl applied follows :
<?xml version="1.0" encoding="iso-8859-1" ?> <!-- edited xmlspy® --> <xsl:stylesheet version="2.1" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:mode streamable="yes" /> <xsl:stream href="e:\test_folder_stream\transactions.xml"> <count> <xsl:value-of select="count(transactions/transaction)" /> </count> </xsl:stream> </xsl:stylesheet>
the output follows :
<?xml version="1.0"?>
ideally should output :
<?xml version="1.0"> <count>2</count>
the script executed follows :
test.js transactions.xsl transactions.xml output.xml
the script not throw error . xsl have written incomplete ? suggestions or links valuable .
thanks in advance tazim.
i don't think there xslt processor available implements xsl:stream
.
saxon 9.3 implements many of streaming features in xslt 2.1 (now xslt 3.0) working draft, not yet xsl:stream instruction. suspect using xslt 1.0 processor. if specify version="2.1" in stylesheet , throw @ xslt 1.0 processor, ignore children of xsl:stylesheet element doesn't understand.
in fact xsl:stream
defined in xslt 3.0 instruction, can't appear child of xsl:stylesheet
- needs go in function or template.
if need streamed processing, copy of saxon 9.3 enterprise edition, , read documentation see subset of working draft implemented. won't able use javascript, unfortunately.
Comments
Post a Comment