ตัวแบ่งบรรทัดใน xsl fop

ฉันใช้ xslt และ fop เพื่อสร้าง PDF จาก xml ใน PDF ฉันต้องการให้ทั้งหมด ‹br/› แทนที่ด้วยการขึ้นบรรทัดใหม่

ใน SalesOrderItem แรก ตัวแบ่งบรรทัดจะอยู่ใน ShortDescription และอันนี้ใช้ได้ดี แต่ใน SalesOrderItem ที่สอง ‹br/› อยู่ใน OrderText และวงเล็บเหลี่ยมจะถูก Escape อย่างที่คุณเห็นจะมี br/ แทนที่จะเป็น ‹br/› ที่นี่ตัวแบ่งบรรทัดไม่ทำงาน ฉันพยายามเปลี่ยนแต่ไม่ได้ผล

xml ของฉันมีลักษณะดังนี้:

     <SalesOrderItem>
    <ReceivingPerson>...</ReceivingPerson>
    <Building />
    <Department>...</Department>
    <Floor />
    <Room />
    <DeliveryAddress>
    </DeliveryAddress>
    <IsFreetext>false</IsFreetext>
    <OrderItemNo>1</OrderItemNo>
    <ProductId>800100</ProductId>
    <ExtProductId />
    <ProductDescShort>Text1  <br/><b>text2</b></ProductDescShort>
    <Quantity>1,00</Quantity>
    <PriceUnit>1</PriceUnit>
    <NetPrice>20,00</NetPrice>
    <TotalNetPrice>20,00</TotalNetPrice>
    <GLAccount>
      <GLAccountId>123</GLAccountId>
      <DescShort />
      <CustomerId>customer1</CustomerId>
    </GLAccount>
    <DeliveryDate>06.04.2017</DeliveryDate>
    <OrderText />
    <UnitOfMeasure id='PCE'>
      <Description>Stück</Description>
    </UnitOfMeasure>
    <Status id='090'>
      <StatusDesc>offen</StatusDesc>
    </Status>
    <Tax id='BB'>
      <Description>19%</Description>
    </Tax>
    <CostDistribution>
      <CostDistributionPositions>
        <CostDistributionPos>
          <CostObject>
            <CostObjectId>1006901</CostObjectId>
            <CostObjectType>COSTCENTER</CostObjectType>
            <CustomerId>customer1</CustomerId>
            <MasterCostObjectId>NP-RNS</MasterCostObjectId>
          </CostObject>
          <Percentage>100,00</Percentage>
        </CostDistributionPos>
      </CostDistributionPositions>
    </CostDistribution>
    <DocumentAttachments />
    <Attributes />
    <ExtGLAccountId />
    <Comment />
    <Supplier supplierId='90025370'>
      <SupplierName>WORDSHOP</SupplierName>
      <SupplierLanguage>de</SupplierLanguage>
      <AddressAssociation type='default' default='true'>
        <Address id='90025370'>
        </Address>
      </AddressAssociation>
      <TermsOfDelivery>
        <Description />
        <LongDescription />
      </TermsOfDelivery>
      <TermsOfPayment>
        <Description>30 Tage netto</Description>
        <LongDescription>30 Tage netto</LongDescription>
        <DiscountDays1>30</DiscountDays1>
        <DiscountDays2>0</DiscountDays2>
        <NetDays />
        <DiscountPerc1>0</DiscountPerc1>
        <DiscountPerc2>0</DiscountPerc2>
      </TermsOfPayment>
    </Supplier>
  </SalesOrderItem>
  <SalesOrderItem>
    <ReceivingPerson>fdf</ReceivingPerson>
    <Building />
    <Department/>
    <Floor />
    <Room />
    <DeliveryAddress>
    </DeliveryAddress>
    <IsFreetext>false</IsFreetext>
    <OrderItemNo>2</OrderItemNo>
    <ProductId>50049411</ProductId>
    <ExtProductId />
    <ProductDescShort>Product desc</ProductDescShort>
    <Quantity>1.670,00</Quantity>
    <PriceUnit>1</PriceUnit>
    <NetPrice>0,01</NetPrice>
    <TotalNetPrice>16,70</TotalNetPrice>
    <GLAccount>
      <GLAccountId>9764955002</GLAccountId>
      <DescShort />
      <CustomerId>customer1</CustomerId>
    </GLAccount>
    <DeliveryDate>30.03.2017</DeliveryDate>
    <OrderText>7090070589&lt;br/&gt;17&lt;br/&gt;13.02.2017&lt;br/&gt;name 1&lt;br/&gt;12345&lt;br/&gt;Musterstadt&lt;br/&gt;Strasse 25&lt;br/&gt;D</OrderText>
    <UnitOfMeasure id='PCE'>
      <Description>Stück</Description>
    </UnitOfMeasure>
    <Status id='090'>
      <StatusDesc>offen</StatusDesc>
    </Status>
    <Tax id='N8'>
      <Description>7%</Description>
    </Tax>
    <CostDistribution>
      <CostDistributionPositions>
        <CostDistributionPos>
          <CostObject>
            <CostObjectId>1006901</CostObjectId>
            <CostObjectType>COSTCENTER</CostObjectType>
            <CustomerId>customer1</CustomerId>
            <MasterCostObjectId>c1</MasterCostObjectId>
          </CostObject>
          <Percentage>100,00</Percentage>
        </CostDistributionPos>
      </CostDistributionPositions>
    </CostDistribution>
    <DocumentAttachments />
    <Attributes />
    <ExtGLAccountId />
    <Comment />
    <Supplier supplierId='90004996'>
      <SupplierName>supplier1</SupplierName>
      <SupplierLanguage>de</SupplierLanguage>
      <AddressAssociation type='default' default='true'>
        <Address id='90004996'>
        </Address>
      </AddressAssociation>
      <TermsOfDelivery>
        <Description />
        <LongDescription />
      </TermsOfDelivery>
      <TermsOfPayment>
        <Description>innerhalb von 14 Tagen ohne Abzug</Description>
        <LongDescription>innerhalb von 14 Tagen ohne Abzug</LongDescription>
        <DiscountDays1>14</DiscountDays1>
        <DiscountDays2>0</DiscountDays2>
        <NetDays />
        <DiscountPerc1>0</DiscountPerc1>
        <DiscountPerc2>0</DiscountPerc2>
      </TermsOfPayment>
    </Supplier>
  </SalesOrderItem>

XSLT ของฉันมีลักษณะดังนี้:

<xsl:template match="br">
<fo:block><xsl:apply-templates/></fo:block>
</xsl:template>
...
<xsl:for-each select="SalesOrder/SalesOrderItems/SalesOrderItem">
...
<xsl:if test="ProductDescShort">
<fo:block><xsl:apply-templates select="ProductDescShort"/></fo:block>
</xsl:if>
...
<xsl:if test="OrderText!=''">
<fo:table-row keep-with-next.within-line="always" keep-with-previous.within-line="always" keep-with-previous.within-column="always" keep-with-previous.within-page="always">
<fo:table-cell/><fo:table-cell number-columns-spanned="3" display-align="before">
  <fo:block position="relative" white-space-collapse="false"  linefeed-treatment="preserve"  start-indent="2.0pt" display-align="before" text-align="start" color="#000000" font-family="Arial" font-size="10.0pt">
    <xsl:apply-templates select="OrderText"/>
  </fo:block>
</fo:table-cell>
...
</xsl:for-each>

แก้ไข:

เปลี่ยนให้แทนแบบนี้แต่มันไม่เปลี่ยน ฉันเดาว่าสตริงการค้นหาแทนที่ของฉันผิด แต่ฉันไม่รู้ว่าต้องแทรกอะไรเพื่อให้ตรงกัน

<xsl:if test="OrderText!=''">
<fo:table-row keep-with-next.within-line="always" keep-with-previous.within-line="always" keep-with-previous.within-column="always" keep-with-previous.within-page="always">
<fo:table-cell/><fo:table-cell number-columns-spanned="3" display-align="before">
<fo:block position="relative" white-space-collapse="false"  linefeed-treatment="preserve"  start-indent="2.0pt" display-align="before" text-align="start" color="#000000" font-family="Arial" font-size="10.0pt">
<xsl:variable name="newtext">
 <xsl:call-template name="string-replace-all">
        <xsl:with-param name="text" select="OrderText" />
         <xsl:with-param name="replace" select="'&amp;lt;br/&amp;gt;'" />
        <xsl:with-param name="by" select="20" />
    </xsl:call-template>
</xsl:variable>
 <xsl:value-of select="$newtext"/>
</fo:block>
</fo:table-cell>
...
<!-- Replace Template -->
<xsl:template name="string-replace-all">
    <xsl:param name="text" />
    <xsl:param name="replace" />
    <xsl:param name="by" />
    <xsl:choose>
        <xsl:when test="$text = '' or $replace = ''or not($replace)" >
            <!-- Prevent this routine from hanging -->
            <xsl:value-of select="$text" />
        </xsl:when>
        <xsl:when test="contains($text, $replace)">
            <xsl:value-of select="substring-before($text,$replace)" />
            <xsl:value-of select="$by" />
            <xsl:call-template name="string-replace-all">
                <xsl:with-param name="text" select="substring-after($text,$replace)" />
                <xsl:with-param name="replace" select="$replace" />
                <xsl:with-param name="by" select="$by" />
            </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="$text" />
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

person j.bergmann    schedule 29.03.2017    source แหล่งที่มา
comment
คุณสามารถแทรกลงในข้อความแทนการใช้ fo:block หากบล็อกที่อยู่รอบๆ มี linefreed-treatment=preserve อย่างไรก็ตาม ฉันไม่เห็นเทมเพลต br ของคุณถูกเรียก br ที่อยู่ใน OrderText ได้ถูกหลบหนีไปยัง br ที่ไหนสักแห่ง   -  person Stefan Hegny    schedule 29.03.2017
comment
br's หนีรอดไปแล้วใน xml ซึ่งฉันไม่มีโอกาสเปลี่ยนแปลง ฉันพยายามแทนที่มันด้วยการขึ้นบรรทัดใหม่ แต่อย่างใดฉันก็ไม่สามารถทำให้มันใช้งานได้ ฉันลองวิธีแก้ปัญหาจากลิงก์แต่ไม่สามารถจับคู่ได้ มีความคิดอะไรบ้าง?   -  person j.bergmann    schedule 29.03.2017
comment
คุณกำลังลองใช้เทมเพลตเพื่อแทนที่ 'lt;br/gt;' ใช่ไหม? และสามารถตรวจสอบได้ว่าเอาต์พุตมีการขึ้นบรรทัดใหม่หรือไม่? หรือการขึ้นบรรทัดใหม่เข้ามาแต่ fop ไม่เคารพ?   -  person Stefan Hegny    schedule 29.03.2017
comment
@StefanHegny ฉันพยายามแทนที่และไม่ได้ใส่อักขระขึ้นบรรทัดใหม่แทน br's โปรดดูการแก้ไขของฉัน   -  person j.bergmann    schedule 30.03.2017
comment
หืม ในการแก้ไขของคุณ คุณจะแทนที่มันด้วย 20 เหรอ? (ประมาณบรรทัดที่ 8)   -  person Stefan Hegny    schedule 30.03.2017
comment
ถูกต้อง ฉันพยายามแล้ว แต่มันไม่ได้แทนที่อะไรเลย   -  person j.bergmann    schedule 30.03.2017
comment
ฉันสามารถทำซ้ำสิ่งนั้นได้ สิ่งที่น่าสนใจคือดูเหมือนว่าต้องการให้สตริง replace ไม่ถูก Escape เช่น '&lt;br/&gt;' ฉันแน่ใจว่าวิซาร์ดบางคนสามารถอธิบายสิ่งนี้ได้ คำใบ้ก็คือในเอาต์พุต (ไม่ได้ถูกแทนที่) มันปรากฏเช่นนั้นทุกประการ...   -  person Stefan Hegny    schedule 30.03.2017


คำตอบ (1)


พารามิเตอร์ใน 'แทนที่' และ 'โดย' ผิดตรงไหน สิ่งนี้ใช้งานได้:

<fo:block position="relative" white-space-collapse="false"  linefeed-treatment="preserve"  start-indent="2.0pt" display-align="before" text-align="start" color="#000000" font-family="Arial" font-size="10.0pt">
<xsl:variable name="newtext">
 <xsl:call-template name="string-replace-all">
        <xsl:with-param name="text" select="OrderText" />
        <xsl:with-param name="replace" select="'&lt;br/&gt;'" />
        <xsl:with-param name="by" select="'&#xa;'" />
    </xsl:call-template>
</xsl:variable>
 <xsl:value-of select="$newtext"/>
    </fo:block>

ใน Oxygen Developer ฉันไม่สามารถทำงานนี้ได้ แต่ในระบบที่กำลังทำงานอยู่ จะต้องมีโปรเซสเซอร์ XSLT อื่น และตัวประมวลผลนั้นก็ใช้งานได้

person j.bergmann    schedule 30.03.2017