如何XSLT格式长日期

时间:2013-11-14 15:04:11

标签: java xml xslt date-format

我有一个传递给XSL转换器的XML对象, 传递的日期是长表示法

<xsl:variable name="nominationEffectiveDate" select="NomApprovalCase/nominationEffectiveDate"></xsl:variable>
<xsl:choose>
   <xsl:when test="$nominationEffectiveDate !=''">
      <xsl:value-of select="java:format(java:java.text.SimpleDateFormat.new('MMM, dd yyyy'), java:java.util.Date.new(number($nominationEffectiveDate)))" />
   </xsl:when>
   <xsl:otherwise>
      <xsl:text><![CDATA[&nbsp;]]>the start of the demand response period<![CDATA[&nbsp;]]></xsl:text>
   </xsl:otherwise>
</xsl:choose>

我添加了一个我的XSL片段日期即将到来,比如'1383264000000',我希望它像'2013年6月1日'。但是,运行transofrmation会产生以下错误。

  

线程“main”中的异常java.lang.VerifyError :(类:customernotify,方法:模板$ dot $ 0签名:(Lcom / sun / org / apache / xalan / internal / xsltc / DOM; Lcom / sun / org / apache / xml / internal / dtm / DTMAxisIterator; Lcom / sun / org / apache / xml / internal / serializer / SerializationHandler; I)V)期望在堆栈上找到double       at java.lang.Class.getDeclaredConstructors0(Native Method)       at java.lang.Class.privateGetDeclaredConstructors(Class.java:2389)       at java.lang.Class.getConstructor0(Class.java:2699)       在java.lang.Class.newInstance0(Class.java:326)       在java.lang.Class.newInstance(Class.java:308)       at com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl.getTransletInstance(TemplatesImpl.java:364)       在com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl.newTransformer(TemplatesImpl.java:394)       at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:649)       at com.enernoc.pe.applications.scheduledbatch.nomapproval.xmlprocessing.GenerateEmailPreview.generate(GenerateEmailPreview.java:30)       at com.enernoc.pe.applications.scheduledbatch.nomapproval.CustomerEmailGenerator.generateHtml(CustomerEmailGenerator.java:65)       at com.enernoc.pe.applications.scheduledbatch.nomapproval.EmailPreviewerPlugin $ EmailPreviewProcessor.process(EmailPreviewerPlugin.java:169)       at com.enernoc.pe.applications.scheduledbatch.nomapproval.EmailPreviewerPlugin $ EmailPreviewProcessor.process(EmailPreviewerPlugin.java:1)       at com.enernoc.pe.applications.scheduledbatch.nomapproval.DqCheckProcessor.process(DqCheckProcessor.java:93)       at com.enernoc.pe.applications.scheduledbatch.nomapproval.DqCheckProcessor.process(DqCheckProcessor.java:1)       at com.enernoc.pe.applications.scheduledbatch.nomapproval.Salesforce.call(Salesforce.java:87)       at com.enernoc.pe.applications.scheduledbatch.nomapproval.EmailPreviewerPlugin $ MyCallable.call(EmailPreviewerPlugin.java:102)       at com.enernoc.pe.applications.scheduledbatch.nomapproval.EmailPreviewerPlugin $ MyCallable.call(EmailPreviewerPlugin.java:1)       在com.enernoc.pe.pipeline.push.framework.AbstractPlugin.call(AbstractPlugin.java:44)       在com.enernoc.pe.pipeline.push.framework.AbstractPlugin.call(AbstractPlugin.java:1)       在com.enernoc.pe.applications.scheduledbatch.Main.main(Main.java:196)

1 个答案:

答案 0 :(得分:0)

尝试类似

的内容
<xsl:when test="number($nominationEffectiveDate)">
    <!-- ... -->
</xsl:when>

针对''的测试无法保护您免受NaN值的影响。