Is this valid using java syntax for xslt? I do not have an xml transformation tool that supports java for my validation so I'm not sure if the syntax is correct. If not could anyone please let me know if there is any other approach that I can take?
So if the RequestedDeliveryDate
is less than current date then add 5 days to current date and that will be the new RequestedDeliveryDate
.
XSLT im using:
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:java="http://xml.apache.org/xslt/java" exclude-result-prefixes="java">
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="/tXML/Message/Order/OrderLines/OrderLine/ShippingInfo/RequestedDeliveryBy">
<xsl:choose>
<xsl:when test="(java:format(java:java.text.SimpleDateFormat.new('MM/dd/yyyy HH:mm'), java:java.util.Date.new()) >= '.')">
<RequestedDeliveryBy>
<xsl:value-of select="java:format(java:java.text.SimpleDateFormat.new('MM/dd/yyyy HH:mm'), java:java.util.Date.new(),5)" />
</RequestedDeliveryBy>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="." />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
Test xml:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<tXML>
<Message>
<Order>
<OrderLines>
<OrderLine>
<ShippingInfo>
<RequestedDeliveryBy>12/04/2015 23:59</RequestedDeliveryBy>
</ShippingInfo>
</OrderLine>
</OrderLines>
</Order>
</Message>
</tXML>