2016-06-22 130 views
0

我有一个使用XSLT将XML转换为JSON的问题,我在转换它时遇到问题。使用XSLT将XML转换为custanized JSON

这是XML输入我提供:

<ArrayOfApiInvoiceReport> 
<ApiInvoiceReport> 
    <BillingAddress1>717 N. ATLANTIC AVE</BillingAddress1> 
    <BillingCity>DAYTONA BEACH</BillingCity> 
    <BillingCountry>US</BillingCountry> 
    <BillingCustomerCode>3001518</BillingCustomerCode> 
    <BillingCustomerName>MAUI NIX - DAYTONA BEACH</BillingCustomerName> 
    <BillingState>FL</BillingState> 
    <BillingTelephone>32118</BillingTelephone> 
    <DivisionCode>09</DivisionCode> 
    <FreightAmount>86.52</FreightAmount> 
    <InvoiceAmount>1041.96</InvoiceAmount> 
    <InvoiceCreatedDate>2016-06-18</InvoiceCreatedDate> 
    <InvoiceItems> 
     <ColorCode>BLK</ColorCode> 
     <GenderCode>M</GenderCode> 
     <InvoiceItemSizes> 
      <InvoiceLineNumber>1000</InvoiceLineNumber> 
      <InvoiceNumber>1011063022016</InvoiceNumber> 
      <InvoicedQuantity>12</InvoicedQuantity> 
      <SizeCode>1SZ</SizeCode> 
      <SizeInvoicedPrice>24.52</SizeInvoicedPrice> 
      <UPC>BBPKC1</UPC> 
     </InvoiceItemSizes> 
     <InvoiceLineNumber>1000</InvoiceLineNumber> 
     <InvoiceNumber>1011063022016</InvoiceNumber> 
     <InvoicedQuantity>12</InvoicedQuantity> 
     <ProductInvoicedPrice>294.24</ProductInvoicedPrice> 
     <ProductName>OVERTIME RIPSTOP HTR</ProductName> 
     <ProductNumber>BBPKC1BLK1SZ</ProductNumber> 
     <SeasonCode>USF16</SeasonCode> 
    </InvoiceItems> 
    <InvoiceItems> 
     <ColorCode>BLU</ColorCode> 
     <GenderCode>M</GenderCode> 
     <InvoiceItemSizes> 
      <InvoiceLineNumber>2000</InvoiceLineNumber> 
      <InvoiceNumber>1011063022016</InvoiceNumber> 
      <InvoicedQuantity>12</InvoicedQuantity> 
      <SizeCode>1SZ</SizeCode> 
      <SizeInvoicedPrice>20.02</SizeInvoicedPrice> 
      <UPC>BBPKL2</UPC> 
     </InvoiceItemSizes> 
     <InvoiceLineNumber>2000</InvoiceLineNumber> 
     <InvoiceNumber>1011063022016</InvoiceNumber> 
     <InvoicedQuantity>12</InvoicedQuantity> 
     <ProductInvoicedPrice>240.24</ProductInvoicedPrice> 
     <ProductName>CORE MEDINA</ProductName> 
     <ProductNumber>BBPKL2BLU1SZ</ProductNumber> 
     <SeasonCode>USF16</SeasonCode> 
    </InvoiceItems> 
    <InvoiceItems> 
     <ColorCode>BRN</ColorCode> 
     <GenderCode>M</GenderCode> 
     <InvoiceItemSizes> 
      <InvoiceLineNumber>3000</InvoiceLineNumber> 
      <InvoiceNumber>1011063022016</InvoiceNumber> 
      <InvoicedQuantity>24</InvoicedQuantity> 
      <SizeCode>1SZ</SizeCode> 
      <SizeInvoicedPrice>8.77</SizeInvoicedPrice> 
      <UPC>BWUFX3</UPC> 
     </InvoiceItemSizes> 
     <InvoiceLineNumber>3000</InvoiceLineNumber> 
     <InvoiceNumber>1011063022016</InvoiceNumber> 
     <InvoicedQuantity>24</InvoicedQuantity> 
     <ProductInvoicedPrice>210.48</ProductInvoicedPrice> 
     <ProductName>RIPPER BLOCK ALL DAY ZF</ProductName> 
     <ProductNumber>BWUFX3BRN1SZ</ProductNumber> 
     <SeasonCode>USF16</SeasonCode> 
    </InvoiceItems> 
    <InvoiceItems> 
     <ColorCode>BLK</ColorCode> 
     <GenderCode>M</GenderCode> 
     <InvoiceItemSizes> 
      <InvoiceLineNumber>4000</InvoiceLineNumber> 
      <InvoiceNumber>1011063022016</InvoiceNumber> 
      <InvoicedQuantity>24</InvoicedQuantity> 
      <SizeCode>1SZ</SizeCode> 
      <SizeInvoicedPrice>8.77</SizeInvoicedPrice> 
      <UPC>BWUFX3</UPC> 
     </InvoiceItemSizes> 
     <InvoiceLineNumber>4000</InvoiceLineNumber> 
     <InvoiceNumber>1011063022016</InvoiceNumber> 
     <InvoicedQuantity>24</InvoicedQuantity> 
     <ProductInvoicedPrice>210.48</ProductInvoicedPrice> 
     <ProductName>RIPPER BLOCK ALL DAY ZF</ProductName> 
     <ProductNumber>BWUFX3BLK1SZ</ProductNumber> 
     <SeasonCode>USF16</SeasonCode> 
    </InvoiceItems> 
    <InvoiceNumber>1011063022016</InvoiceNumber> 
    <InvoiceSentDate>2016-06-18</InvoiceSentDate> 
    <InvoiceStatus>95</InvoiceStatus> 
    <InvoiceTotalQuantity>72.000000</InvoiceTotalQuantity> 
    <OrderNumber>0011353030</OrderNumber> 
    <PurchaseOrder>099THRCBAG160615</PurchaseOrder> 
    <SalesPersonCode>3310</SalesPersonCode> 
    <SeasonCode>USF16</SeasonCode> 
    <ShippingAddress1>717 N. ATLANTIC AVE</ShippingAddress1> 
    <ShippingCity>DAYTONA BEACH</ShippingCity> 
    <ShippingCountry>US</ShippingCountry> 
    <ShippingCustomerCode>3001518</ShippingCustomerCode> 
    <ShippingCustomerName>MAUI NIX - DAYTONA BEACH</ShippingCustomerName> 
    <ShippingMethodCode>006</ShippingMethodCode> 
    <ShippingState>FL</ShippingState> 
    <ShippingTelephone>32118</ShippingTelephone> 
    <TermsCode>DDP</TermsCode> 
    <TrackingNumber>0</TrackingNumber> 
</ApiInvoiceReport> 

这是XSLT,我使用转换的

<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:output encoding="utf-8" method="text" omit-xml-declaration="yes"/> 
<xsl:variable name="nl"> 
    <xsl:text/> 
</xsl:variable> 
<xsl:variable name="tb"> 
    <xsl:text/> 
</xsl:variable> 
<xsl:template match="/*"> 
    <xsl:text>[{</xsl:text> 
    <xsl:value-of select="$nl"/> 
    <!-- Process all the child nodes of the root --> 
    <xsl:apply-templates mode="detect" select="*"> 
     <xsl:with-param name="indent" select="$tb"/> 
    </xsl:apply-templates> 
    <!-- Close the root array --> 
    <xsl:value-of select="$nl"/> 
    <xsl:text/> 
</xsl:template> 
<xsl:template match="*" mode="detect"> 
    <xsl:choose> 
     <xsl:when test="name(preceding-sibling::*[1]) = name(current()) and name(following-sibling::*[1]) != name(current())"> 
      <xsl:apply-templates mode="obj-content" select="."/> 
      <xsl:text>]</xsl:text> 
      <xsl:if test="count(following-sibling::*[name() != name(current())]) > 0">, </xsl:if> 
     </xsl:when> 
     <xsl:when test="name(preceding-sibling::*[1]) = name(current())"> 
      <xsl:apply-templates mode="obj-content" select="."/> 
      <xsl:if test="name(following-sibling::*) = name(current())">, </xsl:if> 
     </xsl:when> 
     <xsl:when test="following-sibling::*[1][name() = name(current())]"> 
      <xsl:choose> 
       <xsl:when test="local-name(current()) = 'ApiInvoiceReport'"> 
        <xsl:apply-templates mode="detect" select="*"/> 
        <xsl:text>}, </xsl:text> 
       </xsl:when> 
       <xsl:otherwise> 
        <xsl:text>"</xsl:text> 
        <xsl:value-of select="name()"/> 
        <xsl:text>" : [</xsl:text> 
        <xsl:apply-templates mode="obj-content" select="."/> 
        <xsl:text>, </xsl:text> 
       </xsl:otherwise> 
      </xsl:choose> 
     </xsl:when> 
     <xsl:when test="count(./child::*) > 0 or count(@*) > 0"> 
      <xsl:text>"</xsl:text> 
      <xsl:value-of select="name()"/>" : [<xsl:apply-templates 
       mode="obj-content" select="."/> 
      <xsl:if test="count(following-sibling::*) > 0">], </xsl:if> 
     </xsl:when> 
     <xsl:when test="count(./child::*) = 0"> 
      <xsl:text>"</xsl:text> 
      <xsl:value-of select="name()"/>" : "<xsl:apply-templates select="."/> 
      <xsl:text>"</xsl:text> 
      <xsl:if test="count(following-sibling::*) > 0">, </xsl:if> 
     </xsl:when> 
    </xsl:choose> 
</xsl:template> 
<xsl:template match="*" mode="obj-content"> 
    <xsl:text>{</xsl:text> 
    <xsl:apply-templates mode="attr" select="@*"/> 
    <xsl:if test="count(@*) > 0 and (count(child::*) > 0 or text())">, </xsl:if> 
    <xsl:apply-templates mode="detect" select="./*"/> 
    <xsl:if test="count(child::*) = 0 and text() and not(@*)"> 
     <xsl:text>"</xsl:text> 
     <xsl:value-of select="name()"/>" : "<xsl:value-of select="text()"/> 
     <xsl:text>"</xsl:text> 
    </xsl:if> 
    <xsl:if test="count(child::*) = 0 and text() and @*"> 
     <xsl:text>: "</xsl:text> 
     <xsl:value-of select="text()"/> 
     <xsl:text>"</xsl:text> 
    </xsl:if> 
    <xsl:text>}</xsl:text> 
    <xsl:if test="position() &lt; last()">, </xsl:if> 
</xsl:template> 
<xsl:template match="@*" mode="attr"> 
    <xsl:text>"</xsl:text> 
    <xsl:value-of select="name()"/>" : "<xsl:value-of select="."/> 
    <xsl:text>"</xsl:text> 
    <xsl:if test="position() &lt; last()">,</xsl:if> 
</xsl:template> 
<xsl:template match="node/@TEXT | text()" name="removeBreaks"> 
    <xsl:param name="pText" select="normalize-space(.)"/> 
    <xsl:choose> 
     <xsl:when test="not(contains($pText, '&#xa;'))"> 
      <xsl:copy-of select="$pText"/> 
     </xsl:when> 
     <xsl:otherwise> 
      <xsl:value-of select="concat(substring-before($pText, '&#xd;&#xa;'), ' ')"/> 
      <xsl:call-template name="removeBreaks"> 
       <xsl:with-param name="pText" select="substring-after($pText, '&#xd;&#xa;')"/> 
      </xsl:call-template> 
     </xsl:otherwise> 
    </xsl:choose> 
</xsl:template> 

我得到的输出如下:

[{"ApiInvoiceReport" : [{"BillingAddress1" : "717 N. ATLANTIC AVE", "BillingCity" : "DAYTONA BEACH", "BillingCountry" : "US", "BillingCustomerCode" : "3001518", "BillingCustomerName" : "MAUI NIX - DAYTONA BEACH", "BillingState" : "FL", "BillingTelephone" : "32118", "DivisionCode" : "09", "FreightAmount" : "86.52", "InvoiceAmount" : "1041.96", "InvoiceCreatedDate" : "2016-06-18", "InvoiceItems" : [{"ColorCode" : "BLK", "GenderCode" : "M", "InvoiceItemSizes" : [{"InvoiceLineNumber" : "1000", "InvoiceNumber" : "1011063022016", "InvoicedQuantity" : "12", "SizeCode" : "1SZ", "SizeInvoicedPrice" : "24.52", "UPC" : "BBPKC1"}], "InvoiceLineNumber" : "1000", "InvoiceNumber" : "1011063022016", "InvoicedQuantity" : "12", "ProductInvoicedPrice" : "294.24", "ProductName" : "OVERTIME RIPSTOP HTR", "ProductNumber" : "BBPKC1BLK1SZ", "SeasonCode" : "USF16"}, {"ColorCode" : "BLU", "GenderCode" : "M", "InvoiceItemSizes" : [{"InvoiceLineNumber" : "2000", "InvoiceNumber" : "1011063022016", "InvoicedQuantity" : "12", "SizeCode" : "1SZ", "SizeInvoicedPrice" : "20.02", "UPC" : "BBPKL2"}], "InvoiceLineNumber" : "2000", "InvoiceNumber" : "1011063022016", "InvoicedQuantity" : "12", "ProductInvoicedPrice" : "240.24", "ProductName" : "CORE MEDINA", "ProductNumber" : "BBPKL2BLU1SZ", "SeasonCode" : "USF16"}, {"ColorCode" : "BRN", "GenderCode" : "M", "InvoiceItemSizes" : [{"InvoiceLineNumber" : "3000", "InvoiceNumber" : "1011063022016", "InvoicedQuantity" : "24", "SizeCode" : "1SZ", "SizeInvoicedPrice" : "8.77", "UPC" : "BWUFX3"}], "InvoiceLineNumber" : "3000", "InvoiceNumber" : "1011063022016", "InvoicedQuantity" : "24", "ProductInvoicedPrice" : "210.48", "ProductName" : "RIPPER BLOCK ALL DAY ZF", "ProductNumber" : "BWUFX3BRN1SZ", "SeasonCode" : "USF16"}, {"ColorCode" : "BLK", "GenderCode" : "M", "InvoiceItemSizes" : [{"InvoiceLineNumber" : "4000", "InvoiceNumber" : "1011063022016", "InvoicedQuantity" : "24", "SizeCode" : "1SZ", "SizeInvoicedPrice" : "8.77", "UPC" : "BWUFX3"}], "InvoiceLineNumber" : "4000", "InvoiceNumber" : "1011063022016", "InvoicedQuantity" : "24", "ProductInvoicedPrice" : "210.48", "ProductName" : "RIPPER BLOCK ALL DAY ZF", "ProductNumber" : "BWUFX3BLK1SZ", "SeasonCode" : "USF16"}], "InvoiceNumber" : "1011063022016", "InvoiceSentDate" : "2016-06-18", "InvoiceStatus" : "95", "InvoiceTotalQuantity" : "72.000000", "OrderNumber" : "0011353030", "PurchaseOrder" : "099THRCBAG160615", "SalesPersonCode" : "3310", "SeasonCode" : "USF16", "ShippingAddress1" : "717 N. ATLANTIC AVE", "ShippingCity" : "DAYTONA BEACH", "ShippingCountry" : "US", "ShippingCustomerCode" : "3001518", "ShippingCustomerName" : "MAUI NIX - DAYTONA BEACH", "ShippingMethodCode" : "006", "ShippingState" : "FL", "ShippingTelephone" : "32118", "TermsCode" : "DDP", "TrackingNumber" : "0"} 

我想看到的输出如下:

[{"BillingAddress1" : "717 N. ATLANTIC AVE", "BillingCity" : "DAYTONA BEACH", "BillingCountry" : "US", "BillingCustomerCode" : "3001518", "BillingCustomerName" : "MAUI NIX - DAYTONA BEACH", "BillingState" : "FL", "BillingTelephone" : "32118", "DivisionCode" : "09", "FreightAmount" : "86.52", "InvoiceAmount" : "1041.96", "InvoiceCreatedDate" : "2016-06-18", "InvoiceItems" : [{"ColorCode" : "BLK", "GenderCode" : "M", "InvoiceItemSizes" : [{"InvoiceLineNumber" : "1000", "InvoiceNumber" : "1011063022016", "InvoicedQuantity" : "12", "SizeCode" : "1SZ", "SizeInvoicedPrice" : "24.52", "UPC" : "BBPKC1"}], "InvoiceLineNumber" : "1000", "InvoiceNumber" : "1011063022016", "InvoicedQuantity" : "12", "ProductInvoicedPrice" : "294.24", "ProductName" : "OVERTIME RIPSTOP HTR", "ProductNumber" : "BBPKC1BLK1SZ", "SeasonCode" : "USF16"}, {"ColorCode" : "BLU", "GenderCode" : "M", "InvoiceItemSizes" : [{"InvoiceLineNumber" : "2000", "InvoiceNumber" : "1011063022016", "InvoicedQuantity" : "12", "SizeCode" : "1SZ", "SizeInvoicedPrice" : "20.02", "UPC" : "BBPKL2"}], "InvoiceLineNumber" : "2000", "InvoiceNumber" : "1011063022016", "InvoicedQuantity" : "12", "ProductInvoicedPrice" : "240.24", "ProductName" : "CORE MEDINA", "ProductNumber" : "BBPKL2BLU1SZ", "SeasonCode" : "USF16"}, {"ColorCode" : "BRN", "GenderCode" : "M", "InvoiceItemSizes" : [{"InvoiceLineNumber" : "3000", "InvoiceNumber" : "1011063022016", "InvoicedQuantity" : "24", "SizeCode" : "1SZ", "SizeInvoicedPrice" : "8.77", "UPC" : "BWUFX3"}], "InvoiceLineNumber" : "3000", "InvoiceNumber" : "1011063022016", "InvoicedQuantity" : "24", "ProductInvoicedPrice" : "210.48", "ProductName" : "RIPPER BLOCK ALL DAY ZF", "ProductNumber" : "BWUFX3BRN1SZ", "SeasonCode" : "USF16"}, {"ColorCode" : "BLK", "GenderCode" : "M", "InvoiceItemSizes" : [{"InvoiceLineNumber" : "4000", "InvoiceNumber" : "1011063022016", "InvoicedQuantity" : "24", "SizeCode" : "1SZ", "SizeInvoicedPrice" : "8.77", "UPC" : "BWUFX3"}], "InvoiceLineNumber" : "4000", "InvoiceNumber" : "1011063022016", "InvoicedQuantity" : "24", "ProductInvoicedPrice" : "210.48", "ProductName" : "RIPPER BLOCK ALL DAY ZF", "ProductNumber" : "BWUFX3BLK1SZ", "SeasonCode" : "USF16"}], "InvoiceNumber" : "1011063022016", "InvoiceSentDate" : "2016-06-18", "InvoiceStatus" : "95", "InvoiceTotalQuantity" : "72.000000", "OrderNumber" : "0011353030", "PurchaseOrder" : "099THRCBAG160615", "SalesPersonCode" : "3310", "SeasonCode" : "USF16", "ShippingAddress1" : "717 N. ATLANTIC AVE", "ShippingCity" : "DAYTONA BEACH", "ShippingCountry" : "US", "ShippingCustomerCode" : "3001518", "ShippingCustomerName" : "MAUI NIX - DAYTONA BEACH", "ShippingMethodCode" : "006", "ShippingState" : "FL", "ShippingTelephone" : "32118", "TermsCode" : "DDP", "TrackingNumber" : "0"}] 

我不希望看到ApiInvoiceReport在JSON的起点文件和josn应该结束]。

我对XSLT的知识非常少,而且我尽我所能,但无法获得预期的输出结果。

在此先感谢!

回答

0

这里是快速回答:

对于以下XSLT:

<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
 
<xsl:output encoding="utf-8" method="text" omit-xml-declaration="yes"/> 
 
<xsl:variable name="nl"> 
 
    <xsl:text/> 
 
</xsl:variable> 
 
<xsl:variable name="tb"> 
 
    <xsl:text/> 
 
</xsl:variable> 
 
<xsl:template match="/*/*"> 
 
    <xsl:text>[{</xsl:text> 
 
    <xsl:value-of select="$nl"/> 
 
    <!-- Process all the child nodes of the root --> 
 
    <xsl:apply-templates mode="detect" select="*"> 
 
     <xsl:with-param name="indent" select="$tb"/> 
 
    </xsl:apply-templates> 
 
    <!-- Close the root array --> 
 
    <xsl:value-of select="$nl"/> 
 
    <xsl:text/>}] 
 
</xsl:template> 
 
<xsl:template match="*" mode="detect"> 
 
    <xsl:choose> 
 
     <xsl:when test="name(preceding-sibling::*[1]) = name(current()) and name(following-sibling::*[1]) != name(current())"> 
 
      <xsl:apply-templates mode="obj-content" select="."/> 
 
      <xsl:text>]</xsl:text> 
 
      <xsl:if test="count(following-sibling::*[name() != name(current())]) > 0">, </xsl:if> 
 
     </xsl:when> 
 
     <xsl:when test="name(preceding-sibling::*[1]) = name(current())"> 
 
      <xsl:apply-templates mode="obj-content" select="."/> 
 
      <xsl:if test="name(following-sibling::*) = name(current())">, </xsl:if> 
 
     </xsl:when> 
 
     <xsl:when test="following-sibling::*[1][name() = name(current())]"> 
 
      <xsl:choose> 
 
       <xsl:when test="local-name(current()) = 'ApiInvoiceReport'"> 
 
        <xsl:apply-templates mode="detect" select="*"/> 
 
        <xsl:text>}, </xsl:text> 
 
       </xsl:when> 
 
       <xsl:otherwise> 
 
        <xsl:text>"</xsl:text> 
 
        <xsl:value-of select="name()"/> 
 
        <xsl:text>" : [</xsl:text> 
 
        <xsl:apply-templates mode="obj-content" select="."/> 
 
        <xsl:text>, </xsl:text> 
 
       </xsl:otherwise> 
 
      </xsl:choose> 
 
     </xsl:when> 
 
     <xsl:when test="count(./child::*) > 0 or count(@*) > 0"> 
 
      <xsl:text>"</xsl:text> 
 
      <xsl:value-of select="name()"/>" : [<xsl:apply-templates 
 
       mode="obj-content" select="."/> 
 
      <xsl:if test="count(following-sibling::*) > 0">], </xsl:if> 
 
     </xsl:when> 
 
     <xsl:when test="count(./child::*) = 0"> 
 
      <xsl:text>"</xsl:text> 
 
      <xsl:value-of select="name()"/>" : "<xsl:apply-templates select="."/> 
 
      <xsl:text>"</xsl:text> 
 
      <xsl:if test="count(following-sibling::*) > 0">, </xsl:if> 
 
     </xsl:when> 
 
    </xsl:choose> 
 
</xsl:template> 
 
<xsl:template match="*" mode="obj-content"> 
 
    <xsl:text>{</xsl:text> 
 
    <xsl:apply-templates mode="attr" select="@*"/> 
 
    <xsl:if test="count(@*) > 0 and (count(child::*) > 0 or text())">, </xsl:if> 
 
    <xsl:apply-templates mode="detect" select="./*"/> 
 
    <xsl:if test="count(child::*) = 0 and text() and not(@*)"> 
 
     <xsl:text>"</xsl:text> 
 
     <xsl:value-of select="name()"/>" : "<xsl:value-of select="text()"/> 
 
     <xsl:text>"</xsl:text> 
 
    </xsl:if> 
 
    <xsl:if test="count(child::*) = 0 and text() and @*"> 
 
     <xsl:text>: "</xsl:text> 
 
     <xsl:value-of select="text()"/> 
 
     <xsl:text>"</xsl:text> 
 
    </xsl:if> 
 
    <xsl:text>}</xsl:text> 
 
    <xsl:if test="position() &lt; last()">, </xsl:if> 
 
</xsl:template> 
 
<xsl:template match="@*" mode="attr"> 
 
    <xsl:text>"</xsl:text> 
 
    <xsl:value-of select="name()"/>" : "<xsl:value-of select="."/> 
 
    <xsl:text>"</xsl:text> 
 
    <xsl:if test="position() &lt; last()">,</xsl:if> 
 
</xsl:template> 
 
<xsl:template match="node/@TEXT | text()" name="removeBreaks"> 
 
    <xsl:param name="pText" select="normalize-space(.)"/> 
 
    <xsl:choose> 
 
     <xsl:when test="not(contains($pText, '&#xa;'))"> 
 
      <xsl:copy-of select="$pText"/> 
 
     </xsl:when> 
 
     <xsl:otherwise> 
 
      <xsl:value-of select="concat(substring-before($pText, '&#xd;&#xa;'), ' ')"/> 
 
      <xsl:call-template name="removeBreaks"> 
 
       <xsl:with-param name="pText" select="substring-after($pText, '&#xd;&#xa;')"/> 
 
      </xsl:call-template> 
 
     </xsl:otherwise> 
 
    </xsl:choose> 
 
</xsl:template> 
 
</xsl:stylesheet>

它产生如下结果:

[{"BillingAddress1" : "717 N. ATLANTIC AVE", "BillingCity" : "DAYTONA BEACH", "BillingCountry" : "US", "BillingCustomerCode" : "3001518", "BillingCustomerName" : "MAUI NIX - DAYTONA BEACH", "BillingState" : "FL", "BillingTelephone" : "32118", "DivisionCode" : "09", "FreightAmount" : "86.52", "InvoiceAmount" : "1041.96", "InvoiceCreatedDate" : "2016-06-18", "InvoiceItems" : [{"ColorCode" : "BLK", "GenderCode" : "M", "InvoiceItemSizes" : [{"InvoiceLineNumber" : "1000", "InvoiceNumber" : "1011063022016", "InvoicedQuantity" : "12", "SizeCode" : "1SZ", "SizeInvoicedPrice" : "24.52", "UPC" : "BBPKC1"}], "InvoiceLineNumber" : "1000", "InvoiceNumber" : "1011063022016", "InvoicedQuantity" : "12", "ProductInvoicedPrice" : "294.24", "ProductName" : "OVERTIME RIPSTOP HTR", "ProductNumber" : "BBPKC1BLK1SZ", "SeasonCode" : "USF16"}, {"ColorCode" : "BLU", "GenderCode" : "M", "InvoiceItemSizes" : [{"InvoiceLineNumber" : "2000", "InvoiceNumber" : "1011063022016", "InvoicedQuantity" : "12", "SizeCode" : "1SZ", "SizeInvoicedPrice" : "20.02", "UPC" : "BBPKL2"}], "InvoiceLineNumber" : "2000", "InvoiceNumber" : "1011063022016", "InvoicedQuantity" : "12", "ProductInvoicedPrice" : "240.24", "ProductName" : "CORE MEDINA", "ProductNumber" : "BBPKL2BLU1SZ", "SeasonCode" : "USF16"}, {"ColorCode" : "BRN", "GenderCode" : "M", "InvoiceItemSizes" : [{"InvoiceLineNumber" : "3000", "InvoiceNumber" : "1011063022016", "InvoicedQuantity" : "24", "SizeCode" : "1SZ", "SizeInvoicedPrice" : "8.77", "UPC" : "BWUFX3"}], "InvoiceLineNumber" : "3000", "InvoiceNumber" : "1011063022016", "InvoicedQuantity" : "24", "ProductInvoicedPrice" : "210.48", "ProductName" : "RIPPER BLOCK ALL DAY ZF", "ProductNumber" : "BWUFX3BRN1SZ", "SeasonCode" : "USF16"}, {"ColorCode" : "BLK", "GenderCode" : "M", "InvoiceItemSizes" : [{"InvoiceLineNumber" : "4000", "InvoiceNumber" : "1011063022016", "InvoicedQuantity" : "24", "SizeCode" : "1SZ", "SizeInvoicedPrice" : "8.77", "UPC" : "BWUFX3"}], "InvoiceLineNumber" : "4000", "InvoiceNumber" : "1011063022016", "InvoicedQuantity" : "24", "ProductInvoicedPrice" : "210.48", "ProductName" : "RIPPER BLOCK ALL DAY ZF", "ProductNumber" : "BWUFX3BLK1SZ", "SeasonCode" : "USF16"}], "InvoiceNumber" : "1011063022016", "InvoiceSentDate" : "2016-06-18", "InvoiceStatus" : "95", "InvoiceTotalQuantity" : "72.000000", "OrderNumber" : "0011353030", "PurchaseOrder" : "099THRCBAG160615", "SalesPersonCode" : "3310", "SeasonCode" : "USF16", "ShippingAddress1" : "717 N. ATLANTIC AVE", "ShippingCity" : "DAYTONA BEACH", "ShippingCountry" : "US", "ShippingCustomerCode" : "3001518", "ShippingCustomerName" : "MAUI NIX - DAYTONA BEACH", "ShippingMethodCode" : "006", "ShippingState" : "FL", "ShippingTelephone" : "32118", "TermsCode" : "DDP", "TrackingNumber" : "0"}] 
+0

其工作,并感谢很多关于快速回应。 –

+0

@SivaSwarna请接受答案 – nawazlj