Conversion Functions are functions that convert the data type of an input value into another data type.
The supported conversion functions are: convert-to-number (convert-to-short-function, convert-to-long-function, convert-to-ushort-function, convert-to-uint-function, convert-to-ulong-function, convert-to-float-function, convert-to-double-function), convert-to-bool and convert-to-string.
Examples:
1. The convert-to-number function converts Boolean or number values to number values: "true" converts into "1" and "false" converts into "0".
The following sample displays the hours worked in each department, for every employee ID. The attribute "greater-than-1200" displays returns "1" if the number of hours is greater than 1200, otherwise it returns "0".
Output:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns:root xmlns:ns="http://www.tempuri.org/XML">
<ns:emp id="1">
<ns:hist hours-worked="300" greater-than-1200="0"/>
<ns:hist hours-worked="500" greater-than-1200="0"/>
<ns:hist hours-worked="3000" greater-than-1200="1"/>
<ns:hist hours-worked="100" greater-than-1200="0"/>
</ns:emp>
<ns:emp id="2">
<ns:hist hours-worked="1000" greater-than-1200="0"/>
<ns:hist hours-worked="8000" greater-than-1200="1"/>
<ns:hist hours-worked="5000" greater-than-1200="1"/>
</ns:emp>
<ns:emp id="3"/>
</ns:root>
2. The convert-to-bool function converts all data types, besides DateTime format, to Boolean values.
All numbers, except for "0", are converted to "true" and "0" is converted to "false".
The following example converts the values for "department" and "hours-worked" into a Boolean value ("true" or "false").
Output:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns:root xmlns:ns="http://www.tempuri.org/XML">
<ns:hist department="Accounting" department-to-bool="false" hours-worked="300" hours-worked-to-bool="true"/>
<ns:hist department="Sales" department-to-bool="false" hours-worked="500" hours-worked-to-bool="true"/>
<ns:hist department="Accounting" department-to-bool="false" hours-worked="1000" hours-worked-to-bool="true"/>
<ns:hist department="Sales" department-to-bool="false" hours-worked="8000" hours-worked-to-bool="true"/>
<ns:hist department="Development" department-to-bool="false" hours-worked="3000" hours-worked-to-bool="true"/>
<ns:hist department="Development" department-to-bool="false" hours-worked="5000" hours-worked-to-bool="true"/>
<ns:hist department="Accounting" department-to-bool="false" hours-worked="100" hours-worked-to-bool="true"/>
</ns:root>
3. The convert-to-string function converts all data types to string values.
The following sample returns the number of hours worked by each employee, in each department, sorted by the employee's ID.
The field hours-worked is converted to string and concatenated with the string "Hours worked:".
Output:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns:root xmlns:ns="http://www.tempuri.org/XML">
<ns:hist emp-id="1" department="Accounting" hours-worked="Hours worked:300"/>
<ns:hist emp-id="1" department="Sales" hours-worked="Hours worked:500"/>
<ns:hist emp-id="1" department="Development" hours-worked="Hours worked:3000"/>
<ns:hist emp-id="1" department="Accounting" hours-worked="Hours worked:100"/>
<ns:hist emp-id="2" department="Accounting" hours-worked="Hours worked:1000"/>
<ns:hist emp-id="2" department="Sales" hours-worked="Hours worked:8000"/>
<ns:hist emp-id="2" department="Development" hours-worked="Hours worked:5000"/>
</ns:root>
4. The convert-to-datetime function converts all data types to date format.
It is mandatory for the input string and the format to be specified.
The following sample converts to date a string, using the declared format. The converted date is used for comparison, together with the date when each employee's personal information has been modified. If the converted date is greater or equal than the date from the Hist table, the value "true" will be returned. Otherwise, the Greater or equal function will return "false".
Output:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns:root xmlns:ns="http://www.tempuri.org/XML">
<ns:dbo.hist emp-id="1" attribute-name="true"/>
<ns:dbo.hist emp-id="1" attribute-name="false"/>
<ns:dbo.hist emp-id="2" attribute-name="true"/>
<ns:dbo.hist emp-id="2" attribute-name="false"/>
<ns:dbo.hist emp-id="1" attribute-name="true"/>
<ns:dbo.hist emp-id="2" attribute-name="false"/>
<ns:dbo.hist emp-id="1" attribute-name="false"/>
</ns:root>
5. The convert-to-byte function converts a number to byte.
The following example converts a constant number to byte, using the mentioned function:
Output:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns:root attribute-name="57" xmlns:ns="http://www.tempuri.org/XML"/>