A perl script for XSLT using MSXML

Last version: https://gist.github.com/1053576

 
 
sub TransformWithArgs {
     my ( $xsltFile , $xmlFile ,128); ">$argsHash ) = @_ ;

     my $template = Win32:: OLE -> new ( 'MSXML2.XSLTemplate.4.0' )
        or die "Couldn't create MSXML2.XSLTemplate object.\n" ;

     my $xsltDoc = 'MSXML2.FreeThreadedDOMDocument.4.0' )
        or "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 = "Msxml2.DOMDocument.4.0" );
    $xmlDoc -> load ( $xmlFile );
     $xmlDoc || "Failed to load $xmlFile\n" ;

     # Note: ? The code can not work here: $xsltProc->{input} = $docXhtml;
    $xsltProc -> LetProperty ( 'input' ,128); ">$xmlDoc );

     # Add parametes of XSLT
     foreach my $key ( keys %$argsHash ) {
        $xsltProc -> addParameter ( $key ,128); ">$argsHash -> { $key });
     }

    $xsltProc -> transform () or "Faied to transform.\n" ;
     my $result = $xsltProc -> { output };

     $result ;
}

相关文章

1. 如何去重 #!/usr/bin/perl use strict; my %hash; while(...
最近写了一个perl脚本,实现的功能是将表格中其中两列的数据...
表的数据字典格式如下:如果手动写MySQL建表语句,确认麻烦,...
巡检类工作经常会出具日报,最近在原有日报的基础上又新增了...
在实际生产环境中,常常需要从后台日志中截取报文,报文的形...
最近写的一个perl程序,通过关键词匹配统计其出现的频率,让...