I am using this this answer to perform XSLT 1.0 tranformation. I intend save the output in another xml file. As such I add,
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);
This produces following error,
Can't coerce UNKNOWN to string in entersub at $LongPath/XML/LibXSLT.pm line 485.
Looking up online, I was able to find this blog which mentions something similar.
Am I missing something obvious?
UPDATE
XML File
<?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 File
<?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>