my xsl looks like below :
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:SimpleDateFormat="java.text.SimpleDateFormat"
xmlns:Date="java.util.Date" exclude-result-prefixes="SimpleDateFormat Date">
<xsl:variable name="s" select="SimpleDateFormat:new(MMM/dd/yyyy-HH/mm/ss/SSS)"/>
<xsl:variable name="date" select="Date:new(number($beginTime))"/>
So now how to call the method format(Date date) of instance 's'?
If I use <xsl:value-of select="s:format($date)" />
, then the error is : prefix must resolve to a namespace : s.
But if I add the namespace like this : xmlns:s="java.text.SimpleDateFormat"
, the <xsl:value-of select="s:format($date)" />
will return default format, not the specified format.
So how can I get the specified format, like MM/dd/yyyy-HH/mm/ss/SSS ?
The Xalan extension in our XSL file can call any Java method and get the value returned to it—which it can use to fill any node or attribute value. XSLT (Extensible Stylesheet Language Transformation) is an amazing language for transforming XML documents into other XML documents.
JavaScript can run XSLT transformations through the XSLTProcessor object. Once instantiated, an XSLTProcessor has an XSLTProcessor. importStylesheet() method that takes as an argument the XSLT stylesheet to be used in the transformation. The stylesheet has to be passed in as an XML document, which means that the .
Definition and Usage. The <xsl:number> element is used to determine the integer position of the current node in the source. It is also used to format a number.
XSLT <xsl:text> The <xsl:text> element is used to write literal text to the output. Tip: This element may contain literal text, entity references, and #PCDATA.
The namespace you need to use is the one which refers to the object type, and pass the variable itself as the first argument in your call:
BTW: You need to put the format argument between apostrophes:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:SimpleDateFormat="java.text.SimpleDateFormat" xmlns:Date="java.util.Date" exclude-result-prefixes="SimpleDateFormat Date">
<xsl:variable name="s" select="SimpleDateFormat:new('MMM/dd/yyyy-HH/mm/ss/SSS')"/>
<xsl:variable name="date" select="Date:new()"/>
<!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<xsl:template match="*">
<Test>
<xsl:value-of select="SimpleDateFormat:format($s,$date)" />
</Test>
</xsl:template>
</xsl:stylesheet>
I hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With