Last version:https://gist.github.com/1053576
sub
TransformWithArgs
{
my
(
$xsltFile
,
$xmlFile
,
$argsHash
)
=
@_
;
my
$template
=
Win32::
OLE
->
new
(
'MSXML2.XSLTemplate.4.0'
)
or
die
"Couldn't create MSXML2.XSLTemplate object.\n"
;
my
$xsltDoc
=
Win32::
OLE
->
new
(
'MSXML2.FreeThreadedDOMDocument.4.0'
)
or
die
"Couldn't create MSXML2.FreeThreadedDOMDocument.4.0 object.\n "
;
$xsltDoc
->
{
async
}
=
"false"
;
$xsltDoc
->
{
resolveExternals
}
=
"false"
;
$xsltDoc
->
load
(
$xsltFile
);
$template
->
{
stylesheet
}
=
$xsltDoc
;
my
$xsltProc
=
$template
->
createProcessor
();
my
$xmlDoc
=
Win32::
OLE
->
new
(
"Msxml2.DOMDocument.4.0"
);
$xmlDoc
->
load
(
$xmlFile
);
$xmlDoc
||
die
"Failed to load $xmlFile\n"
;
# Note: ? The code can not work here: $xsltProc->{input} = $docXhtml;
$xsltProc
->
LetProperty
(
'input'
,
$xmlDoc
);
# Add parametes of XSLT
foreach
my
$key
(
keys
%$argsHash
)
{
$xsltProc
->
addParameter
(
$key
,
$argsHash
->
{
$key
});
}
$xsltProc
->
transform
()
or
die
"Faied to transform.\n"
;
my
$result
=
$xsltProc
->
{
output
};
$result
;
}