<?xml version="1.0"?>

<sx:resources xmlns:sx="http://www.servingxml.com/core">

  <sx:service id="trades">
    <sx:parameter name="feed">
      <sx:defaultValue>NY</sx:defaultValue>
    </sx:parameter>
    <sx:serialize>
      <sx:transform>
        <sx:content ref="trades"/>
      </sx:transform>
    </sx:serialize>
  </sx:service>

  <sx:recordContent id="trades">
    <sx:customRecordReader class="flat2xml.TradeRecordReader"/>
    <sx:recordMapping ref="tradesToXmlMapping"/>
  </sx:recordContent>

  <sx:recordMapping id="tradesToXmlMapping">
    <trades>
      <sx:fieldAttributeMap value="{$feed}" attribute="feed"/>
      <sx:onRecord recordType="trade">
        <trade>
          <sx:fieldAttributeMap field="id" attribute="id"/>
          <sx:elementMap element="trade-date">
            <sx:convertToDateTime format="MM/dd/yyyy H:mm:ss">
              <sx:concat separator=" ">
                <sx:toString value="{trade_date}"/>
                <sx:toString value="{trade_time}"/>
              </sx:concat>
            </sx:convertToDateTime>
          </sx:elementMap>
          <sx:fieldElementMap field="description" element="description"/>
        </trade>
      </sx:onRecord>
      <sx:onRecord recordType="transaction">
        <transaction>
          <sx:fieldAttributeMap field="id" attribute="id"/>
          <sx:fieldElementMap field="reference" element="reference"/>
          <sx:fieldElementMap field="description" element="description"/>
        </transaction>
      </sx:onRecord>
    </trades>
  </sx:recordMapping>

</sx:resources>

