xmlxslt

xsltproc (osx) "not a stylesheet, compilation error". but xml & xsl both work on online tool


managed to get my xsl working at http://www.xmlper.com/ (great tool good recommendation from other stackoverflow comment).

but when I run the same (and now highly stripped down) xml & xsl on my mac os x command line I get "compilation error, Document is not a stylesheet"

Is it a version issue (output of xsltproc below)? i'm running latest mac (10.7) and latest xcode 4.2 (to ensure xml lib etc)? i couldn't find anything about xsltproc not supporting xslt v2.0 (I've tried setting to v1.0 - no difference) I did try and download other xslt processors (e.g. saxon) but got into old java versions and couldn't get the program to run.

hope someone has come across this and has solved it! thanks

Ben

Input xml file

<?xml version="1.0" encoding="utf-8"?>
<resultsfile>
  <planset>
    <voicemail_divert>
      <cost_over_plan>0</cost_over_plan>
      <this_txn_absolutely_cost_subtotal>0</this_txn_absolutely_cost_subtotal>
    </voicemail_divert>
  </planset>
</resultsfile>

xsl

<?xml version="1.0"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:output method="xml"/>
<xsl:template match="@*|node()">
  <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
  </xsl:copy>
</xsl:template>
  <xsl:template match="cost_over_plan">
  <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
  </xsl:copy>
    <extracost_overplan_aspartoftotal>0</extracost_overplan_aspartoftotal>
    <extraqty_overplan_aspartoftotal>0</extraqty_overplan_aspartoftotal>
</xsl:template>
</xsl:stylesheet>

error

$ xsltproc --debug --novalid --nonet f.xml add_extraqtyandcostfields.xsl 
compilation error: file f.xml line 2 element resultsfile
 xsltParseStylesheetProcess : document is not a stylesheet

version info

$ xsltproc -version
Using libxml 20703, libxslt 10124 and libexslt 813
xsltproc was compiled against libxml 20703, libxslt 10124 and libexslt 813
libxslt 10124 was compiled against libxml 20703
libexslt 813 was compiled against libxml 20703

Solution

  • As documented in the manpage, the stylesheet must preceed the XML file in xsltproc's arguments:

    $ xsltproc --debug --novalid --nonet add_extraqtyandcostfields.xsl f.xml
    

    should work.

    Also, your xsltproc doesn't seem to support XSLT 2.0. Luckily, your stylesheet doesn't seem to require new XSLT 2.0 features. You can simply replace <xsl:stylesheet version="2.0" with <xsl:stylesheet version="1.0" to fix the problem.