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
XML.NET ProgrammingProgramming

Avatar of undefined
Last Comment
Gertone (Geert Bormans)

8/22/2022 - Mon
Gertone (Geert Bormans)

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
ASKER
Mani Pazhana

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?
Gertone (Geert Bormans)

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

All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
ASKER
Mani Pazhana

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>
Gertone (Geert Bormans)

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
Gertone (Geert Bormans)

xsl:apply-templates essentialy says... "process the children"
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER
Mani Pazhana

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
Gertone (Geert Bormans)

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
Mani Pazhana

Perfect. It worked.  Thanks.
Gertone (Geert Bormans)

welcome
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
ASKER
Mani Pazhana

Gertone (Geert Bormans)

answered