title: XML Data Type Conversion
body: <p>I have a need to convert all Float and Double data types as defined by a source schema to decimal data types.</p>
  
  <p>We have an existing XSLT that takes an XML document from a third party and transforms it to a XML structure that we can then pass into our 4GL DB appliction. The nice thing about the native 4GL interface is that it can convert an inbound XML into a native Dataset structure. The short fall is that it maps Float and Double data types to character data types.</p>
  
  <p>Is there a way within an XSLT to identify an element that is a Float/Double data type and convert it to a decimal. I was thinking this could be a pre main XSLT step and then pass the output onto the main XSLT.</p>
  
  <p><strong>Sample Schema In:</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;
      &lt;xs:element name="ttPTManifest"&gt;
          &lt;xs:complexType&gt;
              &lt;xs:sequence&gt;
                  &lt;xs:element ref="JobCode"/&gt;
                  &lt;xs:element ref="EstimateHours"/&gt;
                  &lt;xs:element ref="ActualHours"/&gt;
                  &lt;xs:element ref="Density"/&gt;
                  &lt;xs:element ref="NettLitres"/&gt;
                  &lt;xs:element ref="QuitOutLitres"/&gt;
                  &lt;xs:element ref="QuitInLitres"/&gt;
              &lt;/xs:sequence&gt;
          &lt;/xs:complexType&gt;
      &lt;/xs:element&gt;
      &lt;xs:element name="QuitOutLitres" type="xs:double"/&gt;
      &lt;xs:element name="QuitInLitres" type="xs:float"/&gt;
      &lt;xs:element name="PTManifestSonicIn"&gt;
          &lt;xs:complexType&gt;
              &lt;xs:sequence&gt;
                  &lt;xs:element ref="ttPTManifest"/&gt;
              &lt;/xs:sequence&gt;
          &lt;/xs:complexType&gt;
      &lt;/xs:element&gt;
      &lt;xs:element name="JobCode" type="xs:string"/&gt;
      &lt;xs:element name="NettLitres" type="xs:double"/&gt;
      &lt;xs:element name="EstimateHours" type="xs:float"/&gt;
      &lt;xs:element name="Density" type="xs:decimal"/&gt;
      &lt;xs:element name="ActualHours" type="xs:float"/&gt;
  &lt;/xs:schema&gt;
  </code></pre>
  
  <p><strong>Sample XML Data In:</strong></p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;PTManifestSonicIn xsi:noNamespaceSchemaLocation="SampleIn.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
      &lt;ttPTManifest&gt;
          &lt;JobCode&gt;000123&lt;/JobCode&gt;
          &lt;EstimateHours&gt;3.14159E3&lt;/EstimateHours&gt;
          &lt;ActualHours&gt;3.14159E3&lt;/ActualHours&gt;
          &lt;Density&gt;123.456&lt;/Density&gt;
          &lt;NettLitres&gt;3.14159265358979E3&lt;/NettLitres&gt;
          &lt;QuitOutLitres&gt;3.14159265358979E3&lt;/QuitOutLitres&gt;
          &lt;QuitInLitres&gt;3.14159E3&lt;/QuitInLitres&gt;
      &lt;/ttPTManifest&gt;
  &lt;/PTManifestSonicIn&gt;
  </code></pre>
  
  <p><strong>Rerquired Schema Out:</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;
      &lt;xs:element name="ttPTManifest"&gt;
          &lt;xs:complexType&gt;
              &lt;xs:sequence&gt;
                  &lt;xs:element ref="JobCode"/&gt;
                  &lt;xs:element ref="EstimateHours"/&gt;
                  &lt;xs:element ref="ActualHours"/&gt;
                  &lt;xs:element ref="Density"/&gt;
                  &lt;xs:element ref="NettLitres"/&gt;
                  &lt;xs:element ref="QuitOutLitres"/&gt;
                  &lt;xs:element ref="QuitInLitres"/&gt;
              &lt;/xs:sequence&gt;
          &lt;/xs:complexType&gt;
      &lt;/xs:element&gt;
      &lt;xs:element name="QuitOutLitres" type="xs:decimal"/&gt;
      &lt;xs:element name="QuitInLitres" type="xs:decimal"/&gt;
      &lt;xs:element name="PTManifestSonicIn"&gt;
          &lt;xs:complexType&gt;
              &lt;xs:sequence&gt;
                  &lt;xs:element ref="ttPTManifest"/&gt;
              &lt;/xs:sequence&gt;
          &lt;/xs:complexType&gt;
      &lt;/xs:element&gt;
      &lt;xs:element name="JobCode" type="xs:string"/&gt;
      &lt;xs:element name="NettLitres" type="xs:decimal"/&gt;
      &lt;xs:element name="EstimateHours" type="xs:decimal"/&gt;
      &lt;xs:element name="Density" type="xs:decimal"/&gt;
      &lt;xs:element name="ActualHours" type="xs:decimal"/&gt;
  &lt;/xs:schema&gt;
  </code></pre>
  
  <p><strong>Required XML Data Out:</strong></p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;PTManifestSonicIn xsi:noNamespaceSchemaLocation="SampleOut.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
      &lt;ttPTManifest&gt;
          &lt;JobCode&gt;000123&lt;/JobCode&gt;
          &lt;EstimateHours&gt;3141.59&lt;/EstimateHours&gt;
          &lt;ActualHours&gt;3141.59&lt;/ActualHours&gt;
          &lt;Density&gt;123.456&lt;/Density&gt;
          &lt;NettLitres&gt;3141.59265358979&lt;/NettLitres&gt;
          &lt;QuitOutLitres&gt;3141.59265358979&lt;/QuitOutLitres&gt;
          &lt;QuitInLitres&gt;3141.59&lt;/QuitInLitres&gt;
      &lt;/ttPTManifest&gt;
  &lt;/PTManifestSonicIn&gt;
  </code></pre>