Discussions

XML & Web services: Using Java API in XSLT

  1. Using Java API in XSLT (3 messages)

    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

    Threaded Messages (3)

  2. Using Java API in XSLT[ Go to top ]

    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
  3. Using Java API in XSLT[ Go to top ]

    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
  4. Using Java API in XSLT[ Go to top ]

    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