I have a xslt code for getting the date from the database.the code is working correctly and I got the output ,but the problem is the date is not in correct format.here is the result.
output: 2013-05-07T11:27:46.7+02:00
my code is
<xsl:variable name="lastchange" select="shop:ExecStoredProcedure('kt_Lastchange',concat('#account:',$accid,',#itemnumber:',id))"></xsl:variable>
<textarea>
<xsl:value-of select ="$lastchange"/>
</textarea>
anyone can help for getting the correctly format of date?
If you are using
XSLT 1.0 version, use EXSLT - date:format-date date extension
XSLT 2.0 version, use built-in: Formatting Dates and Times date extension
Code
<xsl:variable name="dt" as="xs:dateTime" select="xs:dateTime('2012-10-21T22:10:15')"/>
<xsl:value-of select="format-dateTime($dt, '[Y0001]/[M01]/[D01]')"/>
Related
I want to compare two dates in XSLT (1.0). Here I have mentioned hard coded dates
<xsl:variable name="DATE1" select="ms:format-date(16-FEB-19, 'dd-MMM-yy')" />
<xsl:variable name="DATE2" select="ms:format-date(01-MAY-19, 'dd-MMM-yy')" />
<xsl:if test="$DATE1 $lt; $DATE2">
</xsl:if>
I tried above but not getting proper result.
It looks like you're using some kind of extension function ms:format-date to format the dates. If you can format them as pure numeric YYYYMMDD then you can compare them as numbers. XSLT 1.0 does not offer a "<" operator for strings, let alone for dates.
Do think about moving forward to a later XSLT version (available from third parties) rather than asking the StackOverflow community to help you use a 20-year old version of the language.
I have the below xsl tag
<RectypeLegType>
<xsl:value-of select="../#id" />
</RectypeLegType>
and there can be two possible out come values of this as shown below..
1) <RectypeLegType>fixedLeg_612822</RectypeLegType>
2)<RectypeLegType>floatingLeg_194743</RectypeLegType>
but i want this value to be dispalyed as
<RectypeLegType>fixedLeg</RectypeLegType>
<RectypeLegType>floatingLeg</RectypeLegType>
now please advise how can i achieve this possible outcome i need to do cheanges in my please advise what changes need to be done
Assuming the underscore will always exist in the id attribute:
<RectypeLegType>
<xsl:value-of select="substring-before(../#id, '_')" />
</RectypeLegType>
i have troubles filtering with XSLT, basically i have an xml, where i would like to get only those items where the Due Date falls into interval of 3 months ... i've written the following:
<xsl:variable name="TaskRows" select="/dsQueryResponse/Tasks/Rows/Row[#DueDate > $IsoBeginQuartDate AND #DueDate < $IsoEndQuartDate]"/>
But I get an error: "Failed seting processor stylesheet: expected token ']' found 'NAME' ...
IsoDates are calculated and formated dates in ISO format ...
Any idea, how to do it, or i can't use "AND" when filtering?
PS: i'm using XSLT 1.0
There is case-sensitivity at work here! Try using 'and' instead of 'AND'.
Unfortunately in XSLT 1.0, you can't compare dates to see if a date is between two values.
What you could do is something like this:
<!-- Make sure to format this variables as YYYYMMDD -->
<xsl:variable name="$IsoBeginQuartDate">20130101</xsl:variable>
<xsl:variable name="$IsoBeginQuartDate">20131231</xsl:variable>
<!-- Make sure #DueDate also has the format YYYYMMDD, in this example I assume the DueDate has format YYYY-MM-DD -->
<xsl:variable name="TaskRows" select="/dsQueryResponse/Tasks/Rows/Row[translate(#DueDate, '-', '') > $IsoBeginQuartDate and translate(#DueDate, '-', '') < $IsoEndQuartDate]"/>
You now get errors, because > and < or not supported for strings or dates.
I am trying to compare a date value set in Datepicker (an umbraco document type field) with current date (umbraco.library:FormatDateTime(umbraco.library:CurrentDate()) in an XSLT provided by umbraco cms(version 4.7).
The function i used for this was,
Umbraco.library:DateDiff($expiryDate, $currentDate, 's')
The XSLT throws the following error,
Error occured
System.FormatException: String was not recognized as a valid DateTime.
at System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles)
at umbraco.library.DateDiff(String firstDate, String secondDate, String diffType)
I am sure this is related to some issue with datepicker value. Plain date string instead of datepicker value is working well.
Please help me out if any one went through such a situation.
Edit :
Please see my date diff code used in XSLT below,
<xsl:variable name="currentDate" select="umbraco.library:FormatDateTime(umbraco.library:CurrentDate(), 'yyyy-MM-dd')"/>
Now:<xsl:value-of select="$currentDate"/><br/>
<xsl:variable name="expiryDate" select="umbraco.library:FormatDateTime($node/expiryDate, 'yyyy-MM-dd')"/>
Exp:<xsl:value-of select="$expiryDate"/><br/> // Where **$node/expiryDate** is my datepicker value
<xsl:variable name="diffInSecs" select="umbraco.library:DateDiff($expiryDate, $currentDate, 's')"/>
Diff :<xsl:value-of select="$diffInSecs"/>
You must first make sure that both dates are in the same known format, so you should use this:
<xsl:variable name="currentDate"
select="umbraco.library:FormatDateTime(umbraco.library:CurrentDate(),
'dd/MM/yyyy')" />
and:
<xsl:variable name="formattedExpiryDate"
select="umbraco.library:FormatDateTime($expiryDate, 'dd/MM/yyyy')" />
I have a xsl file for html output. the xsl handles an old format of xml whixh I want to renew now. Therefore I need to rename the old elements names to the new names I'm using the new names in the following xsl code. How can I do this?
I tried
<xsl:template match="OldName">
<NewName><xsl:value-of select="."/></NewName>
</xsl:template>
<xsl:template match="/">
some code... </xsl:template>
and then I tried to access
<xsl:value-of select="NewName"/>
but got nothing while when using the OldName I got the value
If you're using XSLT2, you can use a two-phase transformation.
<xsl:value-of select="NewName"/> looks at the input, not the output. And in the input, there is no NewName. To make use of the NewName, you would have to parse it twice; once renewing the names, and once doing formatting.