Hi, I want to use Java API in XSLT. I want to perform the following.
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:java="------------">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<DateTime>
<xsl:value-of select="java:util.Date.new()"/>
</DateTime>
</xsl:template>
</xsl:stylesheet>
Can anyone let me know what exactly is the namespace to be mentioned for java (xmlns:java="-----")
Thanks,
Soumya
-
Using Java API in XSLT (3 messages)
- Posted by: S S
- Posted on: June 17 2005 12:35 EDT
Threaded Messages (3)
- Using Java API in XSLT by Deepak Kothule on June 17 2005 13:33 EDT
- Using Java API in XSLT by S S on June 17 2005 13:48 EDT
- Using Java API in XSLT by Fredrik Borgh on July 05 2005 05:40 EDT
- Using Java API in XSLT by S S on June 17 2005 13:48 EDT
-
Using Java API in XSLT[ Go to top ]
- Posted by: Deepak Kothule
- Posted on: June 17 2005 13:33 EDT
- in response to S S
This is what I'd used:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xalan="http://xml.apache.org/xalan"
extension-element-prefixes="xalan"
xmlns:java="java">
and transform the document like:
TransformerFactory tFactory = TransformerFactory.newInstance();
// Get the XML input document and the stylesheet.
StreamSource(xslPath);
// Generate the transformer.
Transformer transformer = tFactory.newTransformer(xslSource);
//Write output
File file = new File(outputDir, fileName);
FileWriter writer = new FileWriter(file);
StreamResult result = new StreamResult(writer);
// Perform the transformation.
transformer.transform(new DOMSource(document), result);
writer.close();
- Deepak -
Using Java API in XSLT[ Go to top ]
- Posted by: S S
- Posted on: June 17 2005 13:48 EDT
- in response to Deepak Kothule
Hi Deepak,
Thank you for the response.
I had tried that xmlns:java="java". But it says to me "Namespace 'java' does not contain any functions".
Somewhere on the web, i also saw java namespace mentioned as xmlns:java="http://xml.apache.org/java". But i get the same error message.
I am running this xslt as stand alone.
I have written a sample xml and a stlesheet which displays the data.
Let me know if you have any suggestions.
Thanks,
SOumya -
Using Java API in XSLT[ Go to top ]
- Posted by: Fredrik Borgh
- Posted on: July 05 2005 05:40 EDT
- in response to S S
This example works in both Xalan and Saxon XSLT processors (a static method call example) - it takes a string and formats it (the result is irrelevant):
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:format="com.carmensystems.interbids.util.DateTimeUtil">
<xsl:template match="/">
Value: <xsl:value-of select="format:formatDateTime('20050101')"/>
</xsl:template>
</xsl:stylesheet>
You just specify the class you want your "format:" prefix to use as above, no special Xalan conventions. Hope this helps.
Fredrik