exsl:date-year in OS X

2019-03-04 11:08发布

问题:

As mentioned in this question, I am trying to transform my input xml document using Perl and libXSLT. However, when I try to run the same Perl script on OS X with little addition of following in my xsl file under the

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

I get following error.

xmlXPathCompOpEval: function year not found
Unregistered function
xmlXPathCompiledEval: evaluation failed
runtime error: file trans.xsl line 24 element value-of
XPath evaluation returned no result.

My XSLT file header has following

<?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"/>

Running Perl -v fetches me following

This is perl, v5.8.8 built for darwin-thread-multi-2level Copyright 1987-2006, Larry Wall....

and running uname -a fetches me following

Darwin machine-maci 15.3.0 Darwin Kernel Version 15.3.0: Thu Dec 10 18:40:58 PST 2015; root:xnu-3248.30.4~1/RELEASE_X86_64 x86_64

Why is this error showing up? I thought OS X Vendor has already exsl extensions to their libXSLT. Aren't exsl extensions supported yet?

UPDATE

I tweaked my example a little bit and I got the output as Vendor :- libxslt as suggested by comments below.

回答1:

You must declare date as extension element too:

extension-element-prefixes="exsl date"

Your declared xalan namespace probably will not be necessary when using libxslt. Otherwise that would probably have to be added to the extension-element-prefixes also.