-1

この回答を使用して、XSLT 1.0 変換を実行しています。出力を別のxmlファイルに保存するつもりです。そのように私は付け加えます、

use strict;
use warnings;

use XML::LibXSLT;

my ($xmlfile, $xsltfile,$outfile) = qw/ example.xml trans.xsl out.xml /;

my $xslt = XML::LibXSLT->new;
my $stylesheet = $xslt->parse_stylesheet_file($xsltfile);
my $results    = $stylesheet->transform_file($xmlfile);

$stylesheet->output_file($results,$outfile);

これにより、次のエラーが発生します。

Can't coerce UNKNOWN to string in entersub at $LongPath/XML/LibXSLT.pm line 485.

ネットで調べてみると、似たようなことを書いているこのブログを見つけることができました。

明らかな何かが欠けていますか?

アップデート

XML ファイル

<?xml version="1.0"?>
<?xml-stylesheet type="xsl" href="trans.xsl"?>
<Article>
  <Title>My Article</Title>
  <Authors>
    <Author>Mr. Foo</Author>
    <Author>Mr. Bar</Author>
  </Authors>
  <Body>This is my article text.</Body>
</Article>

XSL ファイル

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">    
  <xsl:output method="xml"/>    
  <xsl:template match="/">
    Article - <xsl:value-of select="/Article/Title"/>
    Authors: <xsl:apply-templates select="/Article/Authors/Author"/>
  </xsl:template>    
  <xsl:template match="Author">
    - <xsl:value-of select="." />
  </xsl:template>    
</xsl:stylesheet>
4

1 に答える 1

0

私は結局自分で問題を見つけました。どうやら

$stylesheet->output_file($results,$outfile);

ステートメントは、指定されたパスでファイルを作成できませんでした。このパスには、存在しないディレクトリがほとんどありませんでした。そのように私はやった

my $dir = dirname($outfile);
mkpath($dir);

その後、出力を に保存できました$outfile

于 2016-06-28T05:45:11.020 に答える