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
LVL 8
mani_saiAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jmcmillan227Commented:
What exactly is the question?
0
mani_saiAuthor Commented:
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>
0
Geert BormansInformation ArchitectCommented:
Try this

<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>
                 <xsl:apply-templates select="cbre:Lease"/>
        </horizon_feed>
    </xsl:template>
    
    <xsl:template match="cbre:Lease">
        <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>
        </lease>
    </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>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

Geert BormansInformation ArchitectCommented:
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
0
mani_saiAuthor Commented:
Thanks. Got it.
0
Geert BormansInformation ArchitectCommented:
welcome
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
XML

From novice to tech pro — start learning today.