troubleshooting Question

XSLT formatting

Avatar of Mani Pazhana
Mani PazhanaFlag for United States of America asked on
ProgrammingXML.NET Programming
6 Comments1 Solution378 ViewsLast Modified:
Here is my XSLT:

<xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:cbre="http://integration.cbre.com/schemas/gcs/hp/horizonhpleasebatch/v1"
    xmlns:common="http://integration.cbre.com/schemas/gcs/common/v1"
    exclude-result-prefixes="cbre common"
    version="1.0">

  <xsl:output indent="yes"/>

  <xsl:template match="cbre:LeaseBatch">
    <horizon_feed>
      <lease>
        <xsl:apply-templates select="cbre:Lease"/>
      </lease>
    </horizon_feed>
  </xsl:template>

  <xsl:template match="cbre:Lease">

    <LeaseID>
      <xsl:value-of select="cbre:LeaseId"/>
    </LeaseID>

    <LeaseCategoryID>
      <xsl:value-of select="cbre:LeaseClassification/common:Code"/>
    </LeaseCategoryID>

    <LeaseStatusID>
      <xsl:value-of select="cbre:LeaseStatus/common:Code"/>
    </LeaseStatusID>

    <LeaseUseID>
      <xsl:value-of select="cbre:SpaceType/common:Code"/>
    </LeaseUseID>

    <HPBuildingLandId>
      <xsl:value-of select="cbre:LocationId"/>
    </HPBuildingLandId>

    <xsl:if test="cbre:MasterLeaseId">
      <ParentLeaseId>
        <xsl:value-of select="cbre:MasterLeaseId"/>
      </ParentLeaseId>
    </xsl:if>

    <LeaseName>
      <xsl:value-of select="cbre:LeaseName"/>
    </LeaseName>

    <xsl:if test="cbre:LeaseCommencementDate">
      <Commence>
        <xsl:call-template name="normalize-date-rev">
          <xsl:with-param name="date" select="cbre:LeaseCommencementDate"></xsl:with-param>
        </xsl:call-template>
      </Commence>
    </xsl:if>

    <xsl:if test="cbre:LeaseExpirationDate">
      <Expiration>
        <xsl:call-template name="normalize-date-rev">
          <xsl:with-param name="date" select="cbre:LeaseExpirationDate"></xsl:with-param>
        </xsl:call-template>
      </Expiration>
    </xsl:if>


    <xsl:for-each select="cbre:LeaseContacts/common:Contact">
      <xsl:if test="common:ContactRole='Tenant'">
        <TenantName>
          <xsl:value-of select="common:ContactName"/>
        </TenantName>
      </xsl:if>

      <xsl:if test="common:ContactRole='Landlord'">
        <LandlordName>
          <xsl:value-of select="common:ContactName"/>
        </LandlordName>
      </xsl:if>

      <xsl:if test="common:ContactRole='HPLeaseManager'">
        <HPLeaseManagerName>
          <xsl:value-of select="common:ContactName"/>
        </HPLeaseManagerName>
      </xsl:if>
    </xsl:for-each>

    <xsl:choose>
      <xsl:when test="cbre:LeaseAreaUOM/common:Code='Acres'">
        <RentableAreaAreas>
          <xsl:value-of select="cbre:LeaseRentableArea"/>
        </RentableAreaAreas>
        <RentableAreaHectares>0</RentableAreaHectares>
        <RentableAreaSF>0</RentableAreaSF>
        <RentableAreaSQM>0</RentableAreaSQM>
      </xsl:when>
      <xsl:when test="cbre:LeaseAreaUOM/common:Code='Hectares'">
        <RentableAreaAreas>0</RentableAreaAreas>
        <RentableAreaHectares>
          <xsl:value-of select="cbre:LeaseRentableArea"/>
        </RentableAreaHectares>
        <RentableAreaSF>0</RentableAreaSF>
        <RentableAreaSQM>0</RentableAreaSQM>
      </xsl:when>
      <xsl:when test="cbre:LeaseAreaUOM/common:Code='SF'">
        <RentableAreaAreas>0</RentableAreaAreas>
        <RentableAreaHectares>0</RentableAreaHectares>
        <RentableAreaSF>
          <xsl:value-of select="cbre:LeaseRentableArea"/>
        </RentableAreaSF>
        <RentableAreaSQM>0</RentableAreaSQM>
      </xsl:when>
      <xsl:when test="cbre:LeaseAreaUOM/common:Code='SQM'">
        <RentableAreaAreas>0</RentableAreaAreas>
        <RentableAreaHectares>0</RentableAreaHectares>
        <RentableAreaSF>0</RentableAreaSF>
        <RentableAreaSQM>
          <xsl:value-of select="cbre:LeaseRentableArea"/>
        </RentableAreaSQM>
      </xsl:when>
      <xsl:otherwise>
        <RentableAreaAreas>0</RentableAreaAreas>
        <RentableAreaHectares>0</RentableAreaHectares>
        <RentableAreaSF>0</RentableAreaSF>
        <RentableAreaSQM>0</RentableAreaSQM>
      </xsl:otherwise>
    </xsl:choose>

    <xsl:if test="cbre:DepositAmount">
      <DepositAmount>
        <xsl:value-of select="cbre:DepositAmount"/>
      </DepositAmount>
    </xsl:if>

    <xsl:if test="cbre:DepositCurrencyCode/common:Code">
      <DepositCurrencyId>
        <xsl:value-of select="cbre:DepositCurrencyCode/common:Code"/>
      </DepositCurrencyId>
    </xsl:if>

    <xsl:if test="cbre:FinancialGuarantee">
      <FinancialGuarantee>
        <xsl:value-of select="cbre:FinancialGuarantee"/>
      </FinancialGuarantee>
    </xsl:if>

    <xsl:if test="cbre:BankorParentGuarantee">
      <BankorParentGuarantee>
        <xsl:value-of select="cbre:BankorParentGuarantee"/>
      </BankorParentGuarantee>
    </xsl:if>

  </xsl:template>

  <xsl:template name="normalize-date-rev">
    <xsl:param name="date"/>
    <xsl:value-of select="format-number(number(substring($date,9,2)), '00')"/>
    <xsl:text>/</xsl:text>
    <xsl:value-of select="format-number(number(substring($date,6,2)), '00')"/>
    <xsl:text>/</xsl:text>
    <xsl:value-of select="format-number(number(substring($date,1,4)), '0000')"/>
  </xsl:template>


</xsl:stylesheet>

-----------------------------------------------------

i am getting this output:


<?xml version="1.0" encoding="utf-8"?>
<horizon_feed>
  <lease>

    <LeaseID>10004</LeaseID>
    <LeaseCategoryID>1</LeaseCategoryID>
    <LeaseStatusID>1</LeaseStatusID>
    <LeaseUseID>2</LeaseUseID>
    <HPBuildingLandId>OVE01</HPBuildingLandId>
    <ParentLeaseId>10004</ParentLeaseId>
    <LeaseName>OVIEDO Villafria</LeaseName>
    <Commence>15/03/2012</Commence>
    <Expiration>31/12/2013</Expiration>
    <LandlordName>SECADES S.A.</LandlordName>
    <HPLeaseManagerName>Pierre Legoff</HPLeaseManagerName>
    <RentableAreaAreas>0</RentableAreaAreas>
    <RentableAreaHectares>0</RentableAreaHectares>
    <RentableAreaSF>0</RentableAreaSF>
    <RentableAreaSQM>0</RentableAreaSQM>
    <DepositAmount>0.00</DepositAmount>
    <DepositCurrencyId>EUR</DepositCurrencyId>
    <FinancialGuarantee>Y</FinancialGuarantee>

    <LeaseID>10005</LeaseID>
    <LeaseCategoryID>2</LeaseCategoryID>
    <LeaseStatusID>2</LeaseStatusID>
    <LeaseUseID>3</LeaseUseID>
    <HPBuildingLandId>DOVE01</HPBuildingLandId>
    <ParentLeaseId>10005</ParentLeaseId>
    <LeaseName>LOVIEDO Villafria</LeaseName>
    <Commence>15/03/2012</Commence>
    <Expiration>31/12/2013</Expiration>
    <LandlordName>SECADES S.A.</LandlordName>
    <HPLeaseManagerName>Pierre Legoff</HPLeaseManagerName>
    <RentableAreaAreas>0</RentableAreaAreas>
    <RentableAreaHectares>0</RentableAreaHectares>
    <RentableAreaSF>0</RentableAreaSF>
    <RentableAreaSQM>0</RentableAreaSQM>
    <DepositAmount>0.00</DepositAmount>
    <DepositCurrencyId>EUR</DepositCurrencyId>
    <FinancialGuarantee>Y</FinancialGuarantee>

  </lease>
</horizon_feed>


------------------------------------------------
i want my output like this:

<?xml version="1.0" encoding="utf-8"?>
<horizon_feed>
  <lease>

    <LeaseID>10004</LeaseID>
    <LeaseCategoryID>1</LeaseCategoryID>
    <LeaseStatusID>1</LeaseStatusID>
    <LeaseUseID>2</LeaseUseID>
    <HPBuildingLandId>OVE01</HPBuildingLandId>
    <ParentLeaseId>10004</ParentLeaseId>
    <LeaseName>OVIEDO Villafria</LeaseName>
    <Commence>15/03/2012</Commence>
    <Expiration>31/12/2013</Expiration>
    <LandlordName>SECADES S.A.</LandlordName>
    <HPLeaseManagerName>Pierre Legoff</HPLeaseManagerName>
    <RentableAreaAreas>0</RentableAreaAreas>
    <RentableAreaHectares>0</RentableAreaHectares>
    <RentableAreaSF>0</RentableAreaSF>
    <RentableAreaSQM>0</RentableAreaSQM>
    <DepositAmount>0.00</DepositAmount>
    <DepositCurrencyId>EUR</DepositCurrencyId>
    <FinancialGuarantee>Y</FinancialGuarantee>

 </lease>
  <lease>

    <LeaseID>10005</LeaseID>
    <LeaseCategoryID>2</LeaseCategoryID>
    <LeaseStatusID>2</LeaseStatusID>
    <LeaseUseID>3</LeaseUseID>
    <HPBuildingLandId>DOVE01</HPBuildingLandId>
    <ParentLeaseId>10005</ParentLeaseId>
    <LeaseName>LOVIEDO Villafria</LeaseName>
    <Commence>15/03/2012</Commence>
    <Expiration>31/12/2013</Expiration>
    <LandlordName>SECADES S.A.</LandlordName>
    <HPLeaseManagerName>Pierre Legoff</HPLeaseManagerName>
    <RentableAreaAreas>0</RentableAreaAreas>
    <RentableAreaHectares>0</RentableAreaHectares>
    <RentableAreaSF>0</RentableAreaSF>
    <RentableAreaSQM>0</RentableAreaSQM>
    <DepositAmount>0.00</DepositAmount>
    <DepositCurrencyId>EUR</DepositCurrencyId>
    <FinancialGuarantee>Y</FinancialGuarantee>

  </lease>
</horizon_feed>


Thanks
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 6 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros