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.
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.