Link to home
Start Free TrialLog in
Avatar of Mani Pazhana
Mani PazhanaFlag for United States of America

asked on

XSLT - Text Warpping issue

Here is my issue:
 Remark tag is having some issue by wrapping into two lines... (we are seeing CR LF in the output)

Here is the Input XMl:

<root xmlns="http://integration.cbre.com/schemas/gcs/batchinvoice/v2">
 <Invoice xmlns:common="http://integration.cbre.com/schemas/gcs/common/v1">
            <ClientId>ATT</ClientId>
            <OriginatingInvoiceId>1970</OriginatingInvoiceId>
            <VendorId>242354</VendorId>
            <AlternativeVendorId>PRV-13-1307</AlternativeVendorId>
            <VendorInvoiceNumber>13-8041</VendorInvoiceNumber>
            <InvoiceDate>2013-08-08T00:00:00</InvoiceDate>
            <InvoiceReceiveDate>2013-08-15T00:00:00</InvoiceReceiveDate>
            <GLDate>2013-08-21T20:53:03.81-05:00</GLDate>
            <Remark>Please repair torn and worn carpet squares on the sales floor.
972-409-0026</Remark>
            <TotalInvoiceAmount>239.23</TotalInvoiceAmount>
            <CurrencyCode>USD</CurrencyCode>
            <StatusCode>
                  <common:Code>Authorized</common:Code>
                  <common:Description>Authorized</common:Description>
            </StatusCode>
            <ClientApprovalNumber>1000119702</ClientApprovalNumber>
            <InvoiceSource>COR</InvoiceSource>
            <NumberOfLines>3</NumberOfLines>
            <InvoiceLineItems>
                  <InvoiceLineItem>
                        <OriginatingInvoiceLineID>4637</OriginatingInvoiceLineID>
                        <POLineNumber>34</POLineNumber>
                        <LineItemDescription>Replace case of carpet tiles on sales floor. 1 tech 2 hrs 2013-08-08T00:00:00</LineItemDescription>
                        <LocationId>ATR002037</LocationId>
                        <BuildingName>7800 N MACARTHUR BLVD SPACE#17</BuildingName>
                        <LineItemAmount>76.000000</LineItemAmount>
                        <GLAccount>
                              <CompanyId>51765</CompanyId>
                              <GLAccountCode>51765</GLAccountCode>
                              <AccountBlock>51765</AccountBlock>
                              <GLAccountDescription>51765</GLAccountDescription>
                        </GLAccount>
                        <AdditionalCoding>
                              <ClientPONumber />
                              <WorkOrderNumber>2037000001</WorkOrderNumber>
                              <WorkOrderCompletedDate>2013-08-19T16:12:38</WorkOrderCompletedDate>
                              <WorkOrderCreatedDate>2013-08-01T12:49:00</WorkOrderCreatedDate>
                              <CodingBlock1>Labor</CodingBlock1>
                              <CodingBlock2>Carpet Replace</CodingBlock2>
                              <CodingBlock4>Replace case of carpet tiles on sales floor. 1 tech 2 hrs</CodingBlock4>
                              <CodingBlock5>Flooring</CodingBlock5>
                        </AdditionalCoding>
                  </InvoiceLineItem>
                  <InvoiceLineItem>
                        <OriginatingInvoiceLineID>4638</OriginatingInvoiceLineID>
                        <POLineNumber>35</POLineNumber>
                        <LineItemDescription>carpet, glue</LineItemDescription>
                        <LocationId>ATR002037</LocationId>
                        <BuildingName>7800 N MACARTHUR BLVD SPACE#17</BuildingName>
                        <LineItemAmount>145.000000</LineItemAmount>
                        <GLAccount>
                              <CompanyId>51765</CompanyId>
                              <GLAccountCode>51765</GLAccountCode>
                              <AccountBlock>51765</AccountBlock>
                              <GLAccountDescription>51765</GLAccountDescription>
                        </GLAccount>
                        <AdditionalCoding>
                              <ClientPONumber />
                              <WorkOrderNumber>2037000001</WorkOrderNumber>
                              <WorkOrderCompletedDate>2013-08-19T16:12:38</WorkOrderCompletedDate>
                              <WorkOrderCreatedDate>2013-08-01T12:49:00</WorkOrderCreatedDate>
                              <CodingBlock1>Materials</CodingBlock1>
                              <CodingBlock2>Carpet Replace</CodingBlock2>
                              <CodingBlock4>carpet, glue</CodingBlock4>
                              <CodingBlock5>Flooring</CodingBlock5>
                        </AdditionalCoding>
                  </InvoiceLineItem>
                  <InvoiceLineItem>
                        <OriginatingInvoiceLineID>4636</OriginatingInvoiceLineID>
                        <POLineNumber>36</POLineNumber>
                        <LineItemDescription>Tax</LineItemDescription>
                        <LocationId>ATR002037</LocationId>
                        <BuildingName>7800 N MACARTHUR BLVD SPACE#17</BuildingName>
                        <LineItemAmount>18.230000</LineItemAmount>
                        <GLAccount>
                              <CompanyId>51765</CompanyId>
                              <GLAccountCode>51765</GLAccountCode>
                              <AccountBlock>51765</AccountBlock>
                              <GLAccountDescription>51765</GLAccountDescription>
                        </GLAccount>
                        <AdditionalCoding>
                              <ClientPONumber />
                              <WorkOrderNumber>2037000001</WorkOrderNumber>
                              <WorkOrderCompletedDate>2013-08-19T16:12:38</WorkOrderCompletedDate>
                              <WorkOrderCreatedDate>2013-08-01T12:49:00</WorkOrderCreatedDate>
                              <CodingBlock1>Tax</CodingBlock1>
                              <CodingBlock2>Carpet Replace</CodingBlock2>
                              <CodingBlock4>Tax</CodingBlock4>
                              <CodingBlock5>Flooring</CodingBlock5>
                        </AdditionalCoding>
                  </InvoiceLineItem>
            </InvoiceLineItems>
      </Invoice>
</root>


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

XSLT:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
                        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                        xmlns="http://integration.cbre.com/schemas/gcs/batchinvoice/v2">
   
      <xsl:output method="xml" indent="yes" />
     
      <xsl:variable name="new-root-node">
            <xsl:text>root</xsl:text>
      </xsl:variable>
 
      <!-- ITP is expecting multiple rows to be wrapped with batch -->
      <xsl:template match="/*">
 
            <!-- Create a new element with new node name. -->
            <xsl:element name="{$new-root-node}">
                  <!-- Copy all children of the root node. -->
                  <xsl:copy-of select="*" />
            </xsl:element>
      </xsl:template>
 
</xsl:stylesheet>


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

can we fix the wrapping issue <Remark> </Remark> in the XSLT?

Thanks
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

What do you need?

Do you want the CRLF to be removed?
then simply do a
<xsl:value-of select="normalize-space(.)"/>
in the template for Remark
Avatar of Mani Pazhana

ASKER

Thanks.

i am only using <xsl:copy-of select="*" /> to copy all the child content.. i am not using  <xsl:value-of select

any idea?
Ah, I missed that, sorry

You need to make a deep copy not using copy-of but using apply-templates (a so called identity copy)

You can only control part of your deep copy, if you take control by having a template for each level in the tree

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns="http://integration.cbre.com/schemas/gcs/batchinvoice/v2">
    
    <xsl:output method="xml" indent="yes" />
    
    <xsl:param name="new-root-node" select="'root'"/>
    
    <!-- ITP is expecting multiple rows to be wrapped with batch -->
    <xsl:template match="/*">
        
        <!-- Create a new element with new node name. -->
        <xsl:element name="{$new-root-node}">
            <!-- Copy all children of the root node. -->
            <xsl:apply-templates select="node()"/>
        </xsl:element>
    </xsl:template>
    
    <xsl:template match="node()">
        <xsl:copy>
            <xsl:copy-of select="@*"/>
            <xsl:apply-templates select="node()"/>
        </xsl:copy>
    </xsl:template>
    
    <xsl:template match="Remark">
        <xsl:copy>
            <xsl:copy-of select="@*"/>
            <xsl:value-of select="normalize-space(.)"/>
        </xsl:copy>
    </xsl:template>
    
</xsl:stylesheet>

Open in new window

Thanks.

do we need to apply this template somewhere in the code...

<xsl:template match="Remark">
        <xsl:copy>
            <xsl:copy-of select="@*"/>
            <xsl:value-of select="normalize-space(.)"/>
        </xsl:copy>
    </xsl:template>
We have it in every template
            <xsl:apply-templates select="node()"/>

Except in the Remark template, because we have no further children there, we just want to show the textual content, with the newlines removed. That is what normalize-space() does
xsl:apply-templates essentialy says... "process the children"
Got it.

i am still having issue.

Can you test this XML:

<root xmlns="http://integration.cbre.com/schemas/gcs/batchinvoice/v2">
 <Invoice xmlns:common="http://integration.cbre.com/schemas/gcs/common/v1">
            <ClientId>ATT</ClientId>
            <OriginatingInvoiceId>1970</OriginatingInvoiceId>
            <VendorId>242354</VendorId>
            <AlternativeVendorId>PRV-13-1307</AlternativeVendorId>
            <VendorInvoiceNumber>13-8041</VendorInvoiceNumber>
            <InvoiceDate>2013-08-08T00:00:00</InvoiceDate>
            <InvoiceReceiveDate>2013-08-15T00:00:00</InvoiceReceiveDate>
            <GLDate>2013-08-21T20:53:03.81-05:00</GLDate>
            <Remark>Please repair torn and worn carpet squares on the sales floor.
972-409-0026</Remark>
            <TotalInvoiceAmount>239.23</TotalInvoiceAmount>
            <CurrencyCode>USD</CurrencyCode>
            <StatusCode>
                  <common:Code>Authorized</common:Code>
                  <common:Description>Authorized</common:Description>
            </StatusCode>
            <ClientApprovalNumber>1000119702</ClientApprovalNumber>
            <InvoiceSource>COR</InvoiceSource>
            <NumberOfLines>3</NumberOfLines>
            <InvoiceLineItems>
                  <InvoiceLineItem>
                        <OriginatingInvoiceLineID>4637</OriginatingInvoiceLineID>
                        <POLineNumber>34</POLineNumber>
                        <LineItemDescription>Replace case of carpet tiles on sales floor. 1 tech 2 hrs 2013-08-08T00:00:00</LineItemDescription>
                        <LocationId>ATR002037</LocationId>
                        <BuildingName>7800 N MACARTHUR BLVD SPACE#17</BuildingName>
                        <LineItemAmount>76.000000</LineItemAmount>
                        <GLAccount>
                              <CompanyId>51765</CompanyId>
                              <GLAccountCode>51765</GLAccountCode>
                              <AccountBlock>51765</AccountBlock>
                              <GLAccountDescription>51765</GLAccountDescription>
                        </GLAccount>
                        <AdditionalCoding>
                              <ClientPONumber />
                              <WorkOrderNumber>2037000001</WorkOrderNumber>
                              <WorkOrderCompletedDate>2013-08-19T16:12:38</WorkOrderCompletedDate>
                              <WorkOrderCreatedDate>2013-08-01T12:49:00</WorkOrderCreatedDate>
                              <CodingBlock1>Labor</CodingBlock1>
                              <CodingBlock2>Carpet Replace</CodingBlock2>
                              <CodingBlock4>Replace case of carpet tiles on sales floor. 1 tech 2 hrs</CodingBlock4>
                              <CodingBlock5>Flooring</CodingBlock5>
                        </AdditionalCoding>
                  </InvoiceLineItem>
                  <InvoiceLineItem>
                        <OriginatingInvoiceLineID>4638</OriginatingInvoiceLineID>
                        <POLineNumber>35</POLineNumber>
                        <LineItemDescription>carpet, glue</LineItemDescription>
                        <LocationId>ATR002037</LocationId>
                        <BuildingName>7800 N MACARTHUR BLVD SPACE#17</BuildingName>
                        <LineItemAmount>145.000000</LineItemAmount>
                        <GLAccount>
                              <CompanyId>51765</CompanyId>
                              <GLAccountCode>51765</GLAccountCode>
                              <AccountBlock>51765</AccountBlock>
                              <GLAccountDescription>51765</GLAccountDescription>
                        </GLAccount>
                        <AdditionalCoding>
                              <ClientPONumber />
                              <WorkOrderNumber>2037000001</WorkOrderNumber>
                              <WorkOrderCompletedDate>2013-08-19T16:12:38</WorkOrderCompletedDate>
                              <WorkOrderCreatedDate>2013-08-01T12:49:00</WorkOrderCreatedDate>
                              <CodingBlock1>Materials</CodingBlock1>
                              <CodingBlock2>Carpet Replace</CodingBlock2>
                              <CodingBlock4>carpet, glue</CodingBlock4>
                              <CodingBlock5>Flooring</CodingBlock5>
                        </AdditionalCoding>
                  </InvoiceLineItem>
                  <InvoiceLineItem>
                        <OriginatingInvoiceLineID>4636</OriginatingInvoiceLineID>
                        <POLineNumber>36</POLineNumber>
                        <LineItemDescription>Tax</LineItemDescription>
                        <LocationId>ATR002037</LocationId>
                        <BuildingName>7800 N MACARTHUR BLVD SPACE#17</BuildingName>
                        <LineItemAmount>18.230000</LineItemAmount>
                        <GLAccount>
                              <CompanyId>51765</CompanyId>
                              <GLAccountCode>51765</GLAccountCode>
                              <AccountBlock>51765</AccountBlock>
                              <GLAccountDescription>51765</GLAccountDescription>
                        </GLAccount>
                        <AdditionalCoding>
                              <ClientPONumber />
                              <WorkOrderNumber>2037000001</WorkOrderNumber>
                              <WorkOrderCompletedDate>2013-08-19T16:12:38</WorkOrderCompletedDate>
                              <WorkOrderCreatedDate>2013-08-01T12:49:00</WorkOrderCreatedDate>
                              <CodingBlock1>Tax</CodingBlock1>
                              <CodingBlock2>Carpet Replace</CodingBlock2>
                              <CodingBlock4>Tax</CodingBlock4>
                              <CodingBlock5>Flooring</CodingBlock5>
                        </AdditionalCoding>
                  </InvoiceLineItem>
            </InvoiceLineItems>
      </Invoice>
</root>

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

when i see the output in Notepad++, i am still seeing CR LF.....

In  Notepad++ we need to set View --->Show symbols --> Show All Characters...
Capture.PNG
ASKER CERTIFIED SOLUTION
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Perfect. It worked.  Thanks.