Recker Recker - 1 year ago 247
Perl Question

xsl:copy-of : could not compile select expression

I am trying to transform an xml file using xsl stylesheet.

xml file

<?xml version="1.0" encoding="utf-8"?>
<ent key="key1">
<text>Error: Could not find </text>
<translation>Another Error similar to previous one.</translation>

xsl file

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="" version="1.0">
<xsl:output method="text"/>
<xsl:template match="msg">
<xsl:for-each select="ent">
<xsl:variable name="current_key" select="@key"/>
<xsl:variable name="Match" select="$translations/msg/ent[@key = $current_key]"/>
<xsl:when test="$Match and normalize-space($Match/text) = normalize-space(.) and (not(@translate) or @translate = true())">
<xsl:copy-of select="$Match/(@key|translation/text())|@context"/>

is one of the attributes but I have not included it in the example xml file.

I am using Perl to do my transformation.
I use the script as mentioned in this answer, when I get the following error,

Invalid expression
compilation error: file test.xsl line 11 element copy-of
xsl:copy-of : could not compile select expression '$Match/(@key|translation/text())|@context'
at line 10

Why is the
expression causing problem?

Answer Source

Using $Match/(@key|translation/text()) is allowed in XPath 2.0 as used in XSLT 2.0 but Perl is likely to use an XSLT 1.0 processor like libxslt. So you would need to spell it out as $Match/@key | $Match/translation/text().

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download