Link to home
Create AccountLog in
Avatar of Mani Pazhana
Mani PazhanaFlag for United States of America

asked on

XSLT formatting

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
Avatar of jmcmillan227
jmcmillan227

What exactly is the question?
Avatar of Mani Pazhana

ASKER

i want to fix my XSLT to get the output shown below:

<?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>
ASKER CERTIFIED SOLUTION
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
The point is that you were making the lease element and were applying the lease nodes to the templates inside that one wrapper <lease>.
If you move the <lease> element construction to the level of cbre:Lease, you get the desired effect
Thanks. Got it.