0

I am Using saxon processor for conversion of XML with XSLT-2.0. but its giving error for XSL file .

Below is the Code for XSL File

<?xml version="1.0"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:plm="http://www.plmxml.org/Schemas/PLMXMLSchema"
xmlns:lxslt="http://www.apache.org/xslt"
xmlns:setfile ="com.teamcenter.rac.cme.cmereport.CMEReportXalanExtension">

<xsl:key name="Occurrence" match="plm:Occurrence | plm:WorkAreaOccurrence" use="@id"/>
<xsl:key name="Operation" match="plm:Operation" use="@id"/>
<xsl:key name="OperationRevision" match="plm:OperationRevision" use="@id"/>
<xsl:key name="Process" match="plm:Process | plm:Operation" use="@id"/>
<xsl:key name="ProcessOccurrence" match="plm:ProcessOccurrence | plm:Occurrence | plm:WorkAreaOccurrence" use="@id"/>
<xsl:key name="ProcessRevision" match="plm:ProcessRevision | plm:OperationRevision" use="@id"/>
<xsl:key name="ProcessView" match="plm:ProcessView" use="@id"/>
<xsl:key name="ProcOpRevision" match="plm:ProcessRevision | plm:OperationRevision" use="@id"/>

<lxslt:component prefix="setfile" elements="copy" functions="setFile setTcFile getCurrentDir
        getCurrentImanFileName getCurrentImanFileNamePrefix getNiceName">
  <lxslt:script lang="javaclass" src="com.teamcenter.rac.cme.cmereport.CMEReportXalanExtension"/>
</lxslt:component>

<xsl:output method="html" indent="yes"/>
<xsl:param name="outDir" select="setfile:getCurrentDir(setfile:new())"/>
<xsl:variable name="roid" select="/plm:PLMXML/plm:ProcessView/@rootRefs"/><!-- rootRef instead of prima.. -->
<!-- Assuming that the primaryOccurrenceRef(& NO MULTIPLE ENTRY POINTS) is always a ProcessOccurrence -->
<xsl:variable name="rpoe" select="key('ProcessOccurrence',$roid)"/>
<xsl:variable name="rprid" select="substring-after($rpoe/@instancedRef,'#')"/>
<xsl:variable name="root" select="key('ProcessRevision',$rprid)"/>

<xsl:template match="/">
    <xsl:call-template name="genData">
        <xsl:with-param name="curProc" select="$root"/>
        <xsl:with-param name="occStr" select="$rpoe/@occurrenceRefs"/>
    </xsl:call-template>
</xsl:template>

<xsl:template name="genData">
<xsl:param name="curProc"/>
<xsl:param name="occStr"/>
    <html>
        <head>
            <title>Process: <xsl:value-of select="$curProc/@name"/></title>
        </head>
        <body BGCOLOR="#FFFFFF" link="#0000FF" vlink="#660066">
            <br/>
                        <!-- Support for Foxfire browser requires specific class="sample" on all table elements -->
            <table class="sample"><!-- main table -->
                <xsl:call-template name="heading">
                    <xsl:with-param name="title" select="'Process Report'"/>
                </xsl:call-template>
                                <tr>
                                        <td>
                                                <xsl:variable name="procid">
                                                        <xsl:call-template name="cleanId">
                                                                <xsl:with-param name="id" select="$curProc/@masterRef"/>
                                                        </xsl:call-template>
                                                </xsl:variable>
                                                <xsl:variable name="proc" select="key('Process',$procid)"/>
                                                <xsl:value-of select="concat($proc/@catalogueId,'/',$curProc/@revision,' - ',$curProc/@name)"/>
                                        </td>
                                </tr>

                <tr><!-- main table:row6::sub level -->
                    <td>
                        <hr color="#000000"/>
                        <table class="sample">
                        <tr>
                            <th>Name</th>
                        </tr>
                        <xsl:call-template name="createCL">
                            <xsl:with-param name="chStr" select="$occStr"/>
                        </xsl:call-template>
                        </table>
                    </td>
                </tr>
            </table>
        </body>
    </html>
</xsl:template>

<xsl:template name="createCL">
<xsl:param name="chStr"/>
    <xsl:variable name="genele" select="key('ProcessOccurrence',$chStr)"/>
                <xsl:if test="name($genele)='ProcessOccurrence'">
                    <xsl:call-template name="creCLext">
                        <xsl:with-param name="genel" select="$genele"/>
                    </xsl:call-template>
                </xsl:if>
</xsl:template>

<xsl:template name="creCLext">
<xsl:param name="genel"/>
    <xsl:variable name="procid" select="substring-after($genel/@instancedRef,'#')"/>
    <xsl:variable name="procele" select="key('ProcOpRevision',$procid)"/><!-- ProcessRevision or OperationRevision -->
    <xsl:variable name="pre1" select="substring-after($genel/@predecessorRefs,'#')"/><!--assuming only one id to be present -->
    <xsl:variable name="pre2" select="key('ProcessOccurrence',$pre1)"/>
    <xsl:variable name="preid" select="substring-after($pre2/@instancedRef,'#')"/>
    <xsl:variable name="prele" select="/plm:PLMXML/*[@id=$preid]"/>
    <tr>
    <td align="center"><a>
        <xsl:attribute name="href">
            <xsl:value-of select="concat($procid,'.html')"/>
        </xsl:attribute>
        <xsl:value-of select="$procele/@name"/>
    </a></td>
     
    </tr>
    <result-document href="concat($procid,'.html')">
    <xsl:call-template name="genopr">
                <xsl:with-param name="curOpr" select="$procele"/>
                <xsl:with-param name="genel" select="$genel"/>
            </xsl:call-template>
    </result-document>
</xsl:template>

<xsl:template name="genopr">
<xsl:param name="curOpr"/>
<xsl:param name="genel"/>
    <html>
        <head>
            <title>Operation: <xsl:value-of select="$curOpr/@name"/></title>
        </head>
        <body BGCOLOR="#FFFFFF" link="#0000FF" vlink="#660066">
            <br/>
            <table class="sample"><!-- main table -->
                <xsl:call-template name="heading">
                    <xsl:with-param name="title" select="'Operation Report'"/>
                </xsl:call-template>
                                <tr>
                                        <td>
                                                <xsl:variable name="procid">
                                                        <xsl:call-template name="cleanId">
                                                                <xsl:with-param name="id" select="$curOpr/@masterRef"/>
                                                        </xsl:call-template>
                                                </xsl:variable>
                                                <xsl:variable name="proc" select="key('Process',$procid)"/>
                                                <xsl:value-of select="concat($proc/@catalogueId,'/',$curOpr/@revision,' - ',$curOpr/@name)"/>
                                        </td>
                                </tr>
                
            </table>
        </body>
    </html>

</xsl:template>

<xsl:template name="heading">
<xsl:param name="title"/>
                <tr><!-- main table:row1::heading-->
                    <th>
                        <div align="left">
                        </div>
                        <div align="center"><b><font size="+2"><xsl:value-of select="$title"/></font></b></div><br/>
                    </th>
                </tr>
</xsl:template>
<xsl:template name="cleanId">
    <xsl:param name="id"/>

    <xsl:choose>
        <xsl:when test="contains($id, '#')">
            <xsl:value-of select="substring-after($id,'#')"/>
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="$id"/>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

</xsl:stylesheet>

Below is the the code where we are calling the transformer for conversion from XML to HTML.

{
         

        // 1. Instantiate a TransformerFactory.
        javax.xml.transform.TransformerFactory tFactory =(SAXTransformerFactory) SAXTransformerFactory.newInstance();

        XslImportResolver myResolve = new XslImportResolver();
        tFactory.setURIResolver( myResolve );

        // 2. Use the TransformerFactory to process the stylesheet Source and
        //                generate a Transformer.
        javax.xml.transform.Transformer transformer = tFactory.newTransformer
                        (new javax.xml.transform.stream.StreamSource(xslLocation));

        // Add debugging output if it is definded in the Registry.
        Registry registry = Registry.getRegistry( this );

        // 3. Use the Transformer to perform the transformation and send the
        //          the output to a Result object.
        transformer.transform( new StreamSource( xmlLocation ),
                new StreamResult( new FileOutputStream( htmlLocation ) ) );
    }

We are getting below error : Static error near {...e:getCurrentDir(setfile:new...} at char 22 in expression in xsl:param/@select on line 22 column 73 of PLMXML_DefaultProcessReport.xsl: XPST0017: Cannot find a 0-argument function named Q{com.teamcenter.rac.cme.cmereport.CMEReportXalanExtension}new()

we remove xalan dependencies and now updated XSLT-2.0 and using Saxon processor.

7
  • First of all, the supported versions of Saxon are 11 and 12 and 10, all XSLT 3.0 processors. If you want to write extension functions in Java check the documentation e.g. saxonica.com/html/documentation10/extensibility/… Commented Aug 4, 2023 at 8:46
  • There are also commercial PE and EE editions of Saxon that have support for e.g. the EXPath file module saxonica.com/html/documentation10/extensions/functions/… Commented Aug 4, 2023 at 8:48
  • @MartinHonnen I don't understood with what you meant by XSLT 3.0 processor , does Saxon support XSLT -2.0 ? Commented Aug 4, 2023 at 9:18
  • Saxon 9.8 and later are XSLT 3 processors. Commented Aug 4, 2023 at 9:21
  • So is there any other processor for XSLT-2.0 onwards for JAVA world ? Commented Aug 4, 2023 at 9:36

1 Answer 1

0

Your stylesheet is using Xalan-specific XSLT extensions to call out to Java code, such as

<lxslt:component prefix="setfile" elements="copy" functions="setFile setTcFile getCurrentDir
        getCurrentImanFileName getCurrentImanFileNamePrefix getNiceName">
  <lxslt:script lang="javaclass" src="com.teamcenter.rac.cme.cmereport.CMEReportXalanExtension"/>
</lxslt:component>

Saxon is able to call out to Java, but the details of how to do so differ from the way Xalan does it (partly for security reasons, partly to cater for the fact that the type system in XSLT 2.0+ is much richer than the 1.0 type system.) So you will need to change this part of your code when moving from Xalan to Saxon.

Sign up to request clarification or add additional context in comments.

2 Comments

Actually i couldnt find anything from the documentation , can you suggest what can i use in place of this ?
I'm sorry you find the documentation confusing, but I'm not going to write a replacement set of documentation just for you. If you could point to a specific part that you find confusing, please ask a more specific question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.