<!---->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:c="http://schemas.microsoft.com/Contact" version="1.0">
  <xsl:output method="xml" omit-xml-declaration="yes" encoding="UTF-8" />
  <xsl:template match="c:contact">
      <Contact>
          <xsl:attribute name="Name">
            <xsl:value-of select="c:NameCollection/c:Name/c:FormattedName" />
          </xsl:attribute>
          <xsl:attribute name="Title">
            <xsl:value-of select="c:NameCollection/c:Name/c:Title" />
          </xsl:attribute>
          <xsl:attribute name="Surname">
            <xsl:value-of select="c:NameCollection/c:Name/c:FamilyName" />
          </xsl:attribute>
          <xsl:attribute name="GivenName">
            <xsl:value-of select="c:NameCollection/c:Name/c:GivenName" />
          </xsl:attribute>
          <xsl:attribute name="MidName">
            <xsl:value-of select="c:NameCollection/c:Name/c:MiddleName" />
          </xsl:attribute>
          <xsl:attribute name="IsCompany">
            <xsl:text>0</xsl:text>
          </xsl:attribute>
          <Notes>
            <xsl:value-of select="c:Notes" />
          </Notes>
          <Sections>
            <Section Name="Personal">
              <Fields>
                <xsl:for-each select="c:EmailAddressCollection/c:EmailAddress">
                  <Field>
                    <xsl:attribute name="Name">
                      <xsl:if test="c:LabelCollection/c:Label='Preferred'">
                        <xsl:text>Primary </xsl:text>
                      </xsl:if>
                      <xsl:text>Email</xsl:text>
                    </xsl:attribute>
                    <xsl:attribute name="Value">
                      <xsl:value-of select="c:Address" />
                    </xsl:attribute>
                  </Field>
                </xsl:for-each>
                <xsl:for-each select="c:PhoneNumberCollection/c:PhoneNumber">
                  <xsl:if test="c:LabelCollection/c:Label='Pager'">
                    <Field>
                      <xsl:attribute name="Name">Pager</xsl:attribute>
                      <xsl:attribute name="Value">
                        <xsl:value-of select="c:Number" />
                      </xsl:attribute>
                    </Field>
                  </xsl:if>
                  <xsl:if test="c:LabelCollection/c:Label='Cellular'">
                    <Field>
                      <xsl:attribute name="Name">Mobile</xsl:attribute>
                      <xsl:attribute name="Value">
                        <xsl:value-of select="c:Number" />
                      </xsl:attribute>
                    </Field>
                  </xsl:if>
                  <xsl:if test="c:LabelCollection/c:Label='Fax'">
                    <xsl:if test="c:LabelCollection/c:Label='Personal'">
                      <Field>
                        <xsl:attribute name="Name">Fax</xsl:attribute>
                        <xsl:attribute name="Value">
                          <xsl:value-of select="c:Number" />
                        </xsl:attribute>
                      </Field>
                    </xsl:if>
                  </xsl:if>
                  <xsl:if test="c:LabelCollection/c:Label='Voice'">
                    <xsl:if test="c:LabelCollection/c:Label='Personal'">
                      <Field>
                        <xsl:attribute name="Name">Phone</xsl:attribute>
                        <xsl:attribute name="Value">
                          <xsl:value-of select="c:Number" />
                        </xsl:attribute>
                      </Field>
                    </xsl:if>
                  </xsl:if>
                </xsl:for-each>
                <xsl:for-each select="c:UrlCollection/c:Url">
                  <xsl:if test="c:LabelCollection/c:Label='Personal'">
                    <Field>
                      <xsl:attribute name="Name">Web</xsl:attribute>
                      <xsl:attribute name="Value">
                        <xsl:value-of select="c:Value" />
                      </xsl:attribute>
                    </Field>
                  </xsl:if>
                </xsl:for-each>
                <xsl:for-each select="c:DateCollection/c:Date">
                  <xsl:if test="c:LabelCollection/c:Label='wab:Birthday'">
                    <Field>
                      <xsl:attribute name="Name">Birthday</xsl:attribute>
                      <xsl:attribute name="Value">
                        <xsl:value-of select="substring(c:Value, 1, 10)" />
                      </xsl:attribute>
                    </Field>
                  </xsl:if>
                  <xsl:if test="c:LabelCollection/c:Label='wab:Anniversary'">
                    <Field>
                      <xsl:attribute name="Name">Anniversary</xsl:attribute>
                      <xsl:attribute name="Value">
                        <xsl:value-of select="substring(c:Value, 1, 10)" />
                      </xsl:attribute>
                    </Field>
                  </xsl:if>
                </xsl:for-each>
                <xsl:for-each select="c:PersonCollection/c:Person">
                  <xsl:if test="c:LabelCollection/c:Label='wab:Spouse'">
                    <Field>
                      <xsl:attribute name="Name">Spouse</xsl:attribute>
                      <xsl:attribute name="Value">
                        <xsl:value-of select="c:FormattedName" />
                      </xsl:attribute>
                    </Field>
                  </xsl:if>
                </xsl:for-each>
                <xsl:for-each select="c:PhysicalAddressCollection/c:PhysicalAddress">
                  <xsl:if test="c:LabelCollection/c:Label='Personal'">
                    <Field>
                      <xsl:attribute name="Name">Street</xsl:attribute>
                      <xsl:attribute name="Value">
                        <xsl:value-of select="c:Street" />
                      </xsl:attribute>
                    </Field>
                    <Field>
                      <xsl:attribute name="Name">City</xsl:attribute>
                      <xsl:attribute name="Value">
                        <xsl:value-of select="c:Locality" />
                      </xsl:attribute>
                    </Field>
                    <Field>
                      <xsl:attribute name="Name">State</xsl:attribute>
                      <xsl:attribute name="Value">
                        <xsl:value-of select="c:Region" />
                      </xsl:attribute>
                    </Field>
                    <Field>
                      <xsl:attribute name="Name">Postcode</xsl:attribute>
                      <xsl:attribute name="Value">
                        <xsl:value-of select="c:PostalCode" />
                      </xsl:attribute>
                    </Field>
                    <Field>
                      <xsl:attribute name="Name">Country</xsl:attribute>
                      <xsl:attribute name="Value">
                        <xsl:value-of select="c:Country" />
                      </xsl:attribute>
                    </Field>
                  </xsl:if>
                </xsl:for-each>
              </Fields>
            </Section>
            <Section Name="Work">
              <Fields>
                <xsl:for-each select="c:PositionCollection/c:Position">
                  <Field>
                    <xsl:attribute name="Name">Office</xsl:attribute>
                    <xsl:attribute name="Value">
                      <xsl:value-of select="c:Office" />
                    </xsl:attribute>
                  </Field>
                  <Field>
                    <xsl:attribute name="Name">Deaprtment</xsl:attribute>
                    <xsl:attribute name="Value">
                      <xsl:value-of select="c:Department" />
                    </xsl:attribute>
                  </Field>
                  <Field>
                    <xsl:attribute name="Name">Title</xsl:attribute>
                    <xsl:attribute name="Value">
                      <xsl:value-of select="c:JobTitle" />
                    </xsl:attribute>
                  </Field>
                  <Field>
                    <xsl:attribute name="Name">Company</xsl:attribute>
                    <xsl:attribute name="Value">
                      <xsl:value-of select="c:Company" />
                    </xsl:attribute>
                  </Field>
                </xsl:for-each>
                <xsl:for-each select="c:PhoneNumberCollection/c:PhoneNumber">
                  <xsl:if test="c:LabelCollection/c:Label='Fax'">
                    <xsl:if test="c:LabelCollection/c:Label='Business'">
                      <Field>
                        <xsl:attribute name="Name">Fax</xsl:attribute>
                        <xsl:attribute name="Value">
                          <xsl:value-of select="c:Number" />
                        </xsl:attribute>
                      </Field>
                    </xsl:if>
                  </xsl:if>
                  <xsl:if test="c:LabelCollection/c:Label='Voice'">
                    <xsl:if test="c:LabelCollection/c:Label='Business'">
                      <Field>
                        <xsl:attribute name="Name">Phone</xsl:attribute>
                        <xsl:attribute name="Value">
                          <xsl:value-of select="c:Number" />
                        </xsl:attribute>
                      </Field>
                    </xsl:if>
                  </xsl:if>
                </xsl:for-each>
                <xsl:for-each select="c:PhysicalAddressCollection/c:PhysicalAddress">
                  <xsl:if test="c:LabelCollection/c:Label='Business'">
                    <Field>
                      <xsl:attribute name="Name">Street</xsl:attribute>
                      <xsl:attribute name="Value">
                        <xsl:value-of select="c:Street" />
                      </xsl:attribute>
                    </Field>
                    <Field>
                      <xsl:attribute name="Name">City</xsl:attribute>
                      <xsl:attribute name="Value">
                        <xsl:value-of select="c:Locality" />
                      </xsl:attribute>
                    </Field>
                    <Field>
                      <xsl:attribute name="Name">State</xsl:attribute>
                      <xsl:attribute name="Value">
                        <xsl:value-of select="c:Region" />
                      </xsl:attribute>
                    </Field>
                    <Field>
                      <xsl:attribute name="Name">Postcode</xsl:attribute>
                      <xsl:attribute name="Value">
                        <xsl:value-of select="c:PostalCode" />
                      </xsl:attribute>
                    </Field>
                    <Field>
                      <xsl:attribute name="Name">Country</xsl:attribute>
                      <xsl:attribute name="Value">
                        <xsl:value-of select="c:Country" />
                      </xsl:attribute>
                    </Field>
                  </xsl:if>
                </xsl:for-each>
                <xsl:for-each select="c:UrlCollection/c:Url">
                  <xsl:if test="c:LabelCollection/c:Label='Business'">
                    <Field>
                      <xsl:attribute name="Name">Web</xsl:attribute>
                      <xsl:attribute name="Value">
                        <xsl:value-of select="c:Value" />
                      </xsl:attribute>
                    </Field>
                  </xsl:if>
                </xsl:for-each>
              </Fields>
            </Section>
          </Sections>
        </Contact>
  </xsl:template>
</xsl:stylesheet>