2017-05-03 4 views
0

ich brauche Datetime-Transformation in XSLT zu tun, sollte EffectiveDate am nächsten Tag des aktuellen Datums und ExpirationDate sollte EffectiveDate + 1 Jahr Können Sie mir bitteXSLT-Transformation Datetime

Eingabe-XML-Hilfe:

<?xml version="1.0" encoding="UTF-8"?> 
<root> 
<Name>Test</Name> 
</root> 

XML-Ausgabe:

<?xml version="1.0" encoding="UTF-8"?> 
<root> 
<EffectiveDate>2017-05-4 13:05:658+0200</EffectiveDate> 
<ExpirationDate>2018-05-4 13:05:658+0200</ExpirationDate> 
</root> 

Probe xslt:

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:template match="/"> 
     <root> 
      <EffectiveDate></EffectiveDate> 
      <ExpirationDate></ExpirationDate> 
     </root> 
    </xsl:template> 
</xsl:stylesheet> 
+0

Wissen Sie, wie das aktuelle Datum zu erhalten: http://stackoverflow.com/questions/26627949/how-to-find-the-current-date-in-xslt-1-0/26628225# 26628225 –

Antwort

0

Dies hängt von Ihrem XSLT-Prozessor ab, aber Sie können dieses Problem mithilfe eines Skripts lösen. In diesem Beispiel wird C# verwendet.

<?xml version="1.0" encoding="utf-8"?> 
<xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:user="urn:my-scripts"> 
    <msxsl:script language="C#" implements-prefix="user"> 
    <msxsl:assembly name="System.Web" /> 
    <msxsl:using namespace="System.Web" /> 
    <![CDATA[ 
      public string GetDate(string DateFormat) 
      { 
      return DateTime.Now.ToString(DateFormat); 
      } 

      public string GetExpirationDate(string DateFormat) 
      { 
      return DateTime.Now.AddYears(1).ToString(DateFormat); 
      } 

     ]]> 
    </msxsl:script> 

    <xsl:output method="xml" omit-xml-declaration="yes" version="1.0" encoding="UTF-8" /> 

    <xsl:template match="/"> 
    <root> 
     <EffectiveDate> 
     <xsl:value-of select="user:GetDate('dddd, dd MMMM yyyy')"/> 
     </EffectiveDate> 
     <ExpirationDate> 
     <xsl:value-of select="user:GetExpirationDate('dddd, dd MMMM yyyy')"/> 
     </ExpirationDate> 
    </root> 
    </xsl:template> 

</xsl:stylesheet>