The following is the xsd format I've currently got:
2012-08-23T00:05:27Z
I want to convert this into the following xsl format:
08/23/2012 05:27 AM
xsl:value-of select="#CreatedDate" />
CreatedDate is my variable.
Assuming this is about XSLT (which I am not at all sure about), the following code:
<xsl:value-of select="concat(
substring(#CreatedDate, 6, 2), '/',
substring(#CreatedDate, 9, 2), '/',
substring(#CreatedDate, 1, 4)
)"/>
will produce a result of "08/23/2012". The rest is left as an exercise for the reader. :-)
Related
I am trying to pad an output in XSLT with variables being multiplied in XSLT 1.0. I cannot use the format-number because it will auto-round the numbers but I need to get the decimals in place. I can get this to work when I use column formatting within the XML, but since this has multiple column formats within the value-of-select, it does not seem to work here and obey the 7 in the code below:
<xsl:value-of select="substring(E_BaseRate * E_NormalHours * 2, 1, 7)" disable-output-escaping="yes"/>
The output I am getting is: 1601.93 translated to 160193 but I need to get the result of 0160193. Is there a way to do this?
I broke this out to give you an idea. You could use as is or put it all together into one select...
<xsl:variable name="numToString" select="string(160193)"/>
<xsl:variable name="numLen" select="string-length($numToString)"/>
<xsl:variable name="value" select="concat(substring('0000000', 1, 7 - $numLen), $numToString)"/>
Given a set of 'numbers' 0242, 0980, 0526, 1732, ...
How can I transform them to look like 24,2 98,0 52,6 173,2 ?
I'm trying xsl:value-of select="format_number(0242,'#,##'), but that would produce 2,42. With the '##,#' the output is 2,4,2
Cheers.
First, define a custom decimal format and place it at the top level of your stylesheet:
<xsl:decimal-format decimal-separator="," grouping-separator="."/>
Then you can use:
<xsl:value-of select="format-number(0242 div 10, '#,0')"/>
to get 24,2 and so on.
Alternatively, you could use:
<xsl:value-of select="translate(format-number(0242 div 10, '#.0'), '.', ',')"/>
You can divide it by 10 to get the number right, then format it.
<xsl:value-of select="format-number(node() div 10, '#.0')" />
Please note that I used a dot instead of the comma to use the decimal point operator (for operators see definition on w3schools).
I have a filed value like "+000002030" need to convert it to "20.30" how can i do this using XSLT. This value "+000002030" is the dynamic one any value it can come.Please let me know how we can convert it.
In XSLT 1.0, use:
<xsl:value-of select="format-number(translate(value, '+', '') div 100, '#.00')"/>
To make this future-proof, use:
<xsl:value-of select="format-number(number(translate(value, '+', '')) div 100, '#.00')"/>
This will work the same in both XSLT 1.0 and XSLT 2.0.
A solution in XSLT-2.0 would be
<xsl:value-of select="format-number(number('+000002030') div 100, '#.00')"/>
How can I change below two fields, format of dateTime in XSLT.
DateTime format
<startdate>2002-05-30T09:30:10+06:00</startdate>
<MidDate>2002-05-30T09:30:10+06:00</MidDate>
I needed as:
<startdate>2002-05-30 09:30:10</startdate>
<MidDate>2002-05-30 9:30</MidDate>
Within XSLT 1.0 you can use substring() as follows:
<xsl:value-of select="substring('2002-05-30T09:30:10+06:00', 1, 10)" /><xsl:text> </xsl:text><xsl:value-of select="substring('2002-05-30T09:30:10+06:00', 12, 8)" />
Above will output:
2002-05-30 09:30:10
If you don't want the seconds attached, you simply adjust the substring a little:
<xsl:value-of select="substring('2002-05-30T09:30:10+06:00', 1, 10)" /><xsl:text> </xsl:text><xsl:value-of select="substring('2002-05-30T09:30:10+06:00', 12, 5)" />
Which will output:
2002-05-30 9:30
If you are able to use XSLT 2.0, you can use format-date() as described in the standard documentation: Formatting Date and Times
<xsl:value-of select="format-date('2002-05-30T09:30:10+06:00', '[Y01]-[M01]-[D01] [H]:[m]:[s]')" />
I am trying to generate a .csv from an xml file which includes a count of "OtherEmployees" with a date of birth prior to a date (e.g. 01/01/1970) and I am unsure of the syntax.
Note that the dates are currently in dd/mm/yyyy format.
This is an example of the xml -
<Companies>
<Company>
<CompanyReference>00000060</CompanyReference>
<Contact>
<PersonID>63</PersonID>
<Title>Mrs</Title>
<Forename>EXAMPLE</Forename>
<Middlename/>
<Surname>NAME</Surname>
<DOB>27/05/1928</DOB>
</Contact>
<OtherEmployees>
<OtherEmployee>
<PersonID>28870</PersonID>
<Title>Miss</Title>
<Forename>EXAMPLE</Forename>
<Middlename/>
<Surname>NAME2</Surname>
<DOB>03/05/1953</DOB>
</OtherEmployee>
<OtherEmployee>
<PersonID>28871</PersonID>
<Title>Miss</Title>
<Forename>EXAMPLE</Forename>
<Middlename/>
<Surname>NAME3</Surname>
<DOB>11/07/1961</DOB>
</OtherEmployee>
</OtherEmployees>
</Company>
I was able to get as far as a count of OtherEmployees with a date of birth with the following -
<xsl:value-of select="count(OtherEmployees/OtherEmployee[DOB])"/>
However I now need to compare the DOB with another date - say 01/01/1970 and only return the OtherEmployee in the count if they have a date of birth before 01/01/1970.
With XSLT 2.0 you can make use of the xs:date data type e.g.
<xsl:value-of select="count(OtherEmployees/OtherEmployee[DOB and xs:date(concat(substring(DOB, 7), '-', substring(DOB, 4, 2), '-', substring(DOB, 1, 2))) lt xs:date('1970-01-01')])"/>
With XSLT 1.0 you can easily convert your data format dd/mm/yyyy to a number yyyymmdd and compare on that:
<xsl:value-of select="count(OtherEmployees/OtherEmployee[DOB and number(concat(substring(DOB, 7), substring(DOB, 4, 2), substring(DOB, 1, 2))) < 19700101])"/>