Hi,
Requirements:
Need to find the DAY-NAME from the date.
I used the XSL function in my XSL file.
<xsl:function name="functx:day-of-week-name-en" as="xs:string"
xmlns:functx="http://www.functx.com">
<xsl:param name="date" as="xs:anyAtomicType?" />
<xsl:sequence
select="('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday')[functx:day-of-week($date) + 1]" />
</xsl:function>
and I use this piece of code to call the function:
Declare a variable 'sDate'
<xsl:variable name="sDate">
<xsl:value-of select="input1/date1"/>
</xsl:variable>
And pass the variable 'sDate' as parameter to the function:
<xsl:element>
<xsl:value-of select="functx:day-of-week-name-en($sDate)" />
</xsl:element>
This is the Java code for Transformation:
public class XMLXSLT {
public static void main(String[] args) throws TransformerException,
TransformerConfigurationException,
FileNotFoundException, IOException{
TransformerFactory tFactory =
TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer(new StreamSource("<PathName>/DateOfWeek.xsl"));
transformer.transform(new StreamSource("<PathName>/date.xml"), new StreamResult(new FileOutputStream("<PathName>/dateout.xml")));
System.out.println("** The output is written in **");
}
}
The following error is thrown while executing the above code:
Compiler warnings:
file:///Users/padmanaban/Padmanaban/EclipseWorkspace/XMLXSLTTest/DateOfWeek.xsl: line 41: You cannot call an element ''
ERROR: 'The first argument to the non-static Java function 'dayOfWeekNameEn' is not a valid object reference.'
FATAL ERROR: 'Could not compile stylesheet'
Exception in thread "main" javax.xml.transform.TransformerConfigurationException: Could not compile stylesheet
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:830)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:624)
at XMLXSLT.main(XMLXSLT.java:25)
Can anyone help on resolve this?
Thanks,
Padmanaban