Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml exsl:文档工作不正常_Xml_Perl_Xslt_Exslt - Fatal编程技术网

Xml exsl:文档工作不正常

Xml exsl:文档工作不正常,xml,perl,xslt,exslt,Xml,Perl,Xslt,Exslt,在Windows7上,我尝试使用PerlV5.8.8和libXSLT版本1.66转换单个文档。这是我的用例的低调版本 Perl脚本 use strict; use warnings; use File::Path; use File::Spec; use File::Basename; use XML::LibXSLT; use XML::LibXML; use Getopt::Std; my $isfile; my ($xmlfile,$xsltfile,$samplefile) = qw

在Windows7上,我尝试使用PerlV5.8.8和libXSLT版本1.66转换单个文档。这是我的用例的低调版本

Perl脚本

use strict;
use warnings;
use File::Path;
use File::Spec;
use File::Basename;
use XML::LibXSLT;
use XML::LibXML;
use Getopt::Std;

my $isfile;

my ($xmlfile,$xsltfile,$samplefile) = qw/ Example.xml trans.xsl sample.xml/;
my %opts = ();
getopts('o:',\%opts);

my $outPath = $opts{'o'};
die "Resource Location/Directory not specified" if !defined($outPath);

if(-f $samplefile)
{
    $isfile = "true";
    print "File is present\n";
}
else
{
    $isfile = "false";
    print "File is absent\n";
}

my %args = ( "isfile" => $isfile,"outpath" => $outPath, );
my $xslt = XML::LibXSLT->new;
my $stylesheet = $xslt->parse_stylesheet_file($xsltfile);

     my $security = XML::LibXSLT::Security->new();
     $security->register_callback( read_file  => sub { return 1;} );
     $security->register_callback( write_file => sub { return 1;} );

     $stylesheet->security_callbacks( $security );

my $results  = $stylesheet->transform_file($xmlfile,XML::LibXSLT::xpath_to_string(%{args}));

0;
XSL文件

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xalan="http://xml.apache.org/xslt" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:exsl="http://exslt.org/common" 
    xmlns:date="http://exslt.org/dates-and-times"
    extension-element-prefixes="exsl">

    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" media-type="text/xml"/>

    <xsl:param name="isfile"/>
    <xsl:param name="outpath"/>

    <xsl:variable name="current-year">
        <xsl:value-of select="date:year()"/>
    </xsl:variable>

    <xsl:template match="/">
         <xsl:if test="$isfile = 'true'">
                 <exsl:document href = "{$outpath}" method="xml" version="1.0" encoding="UTF-8" indent="yes">
                 Article:- <xsl:value-of select="exsl:node-set(/Article/Title)|exsl:node-set(/Article/Title)/@context"/>
                Authors:- <xsl:apply-templates select="/Article/Authors/Author"/>
            </exsl:document>
        </xsl:if>
    </xsl:template>

</xsl:stylesheet>
无法在指定路径中创建文件。相反,当我在我的
XSLT
目录中执行
DIR
ls
操作时(我保存转换脚本、xsl文件和输入xml文件的地方),我得到了以下结果

%5Cuser%5CDocuments%5CXSLT%5Cdir1%5Cdir2%5Coutput1.xml dir1/Example.xml sample.xml Transform.pl trans.xsl

但是,当我在命令行参数上为选项
-o
提供路径时,如下所示

C:\user\Documents\XSLT\dir1\dir2\output1.xml

将在提供的相应路径中创建该文件

1) 为什么当我提供Windows特定路径时,
exsl document
表现得很奇怪

2) 另外,为什么要将
%5C
(相当于
/
)添加到路径中


3) 它不明白如何用路径分隔符将Windows特定的路径解释为
/

我认为
%5C
“\”
而不是
“/”
,我认为问题只是你没有提供URI,而是提供了一个路径。因此,请尝试使用
-ofile:///C:/user/Documents/XSLT/dir1/dir2/output1.xml
。我认为
%5C
“\”
而不是
“/”
,我认为问题在于您没有提供URI,而是提供路径。因此,请尝试使用
-ofile:///C:/user/Documents/XSLT/dir1/dir2/output1.xml
<?xml version="1.0"?>
<?xml-stylesheet type="xsl" href="trans.xsl"?>
<Article>
  <Title context="This article">My Article</Title>
  <Authors>
    <Author>Mr. Foo</Author>
    <Author>Mr. Bar</Author>
  </Authors>
  <Body>This is my article text.</Body>
</Article>
perl Transform.pl -o C:\user\Documents\XSLT\dir1\dir2\output1.xml