xml xsl转换匹配整个文档中的标记

时间:2015-02-18 09:35:14

标签: xml xslt pdf-generation xsl-fo

我有xml文档,需要xsl(xsl-fo)转换才能在包含特定标记的子节点中应用pdf生成,如“粗体”,“斜体”等,这些标记可以出现在文本的任何位置。

<?xml version="1.0" encoding="utf-8"?>
<root>
  <QuoteNumber>Q_ML/0/137088123123</QuoteNumber>
  <QuotationType>Type of Quote</QuotationType>
  <Insured>Name of insured, its not me</Insured>
  <ProposalDate>10/10/2013</ProposalDate>
  <Jurisdiction>Worldwide <bold>(Excluding USA and Canada)</bold> unless specifically stated otherwise</Jurisdiction>
  <Insurer>Some stupid company</Insurer>
  <ProposalFormDate>10/10/2013</ProposalFormDate>
  <ValidUntil>31/10/2014</ValidUntil>
  <Date>19/02/2015</Date>
  <ProductType>ML</ProductType>
  <Region>AUS</Region>
  <NZStandardnPoorsText />
  <InsurancePeriodFrom>31/10/2014</InsurancePeriodFrom>
  <InsurancePeriodTo>31/10/2015</InsurancePeriodTo>
  <Premiums>
    <PremiumText>
      To comply with the <bold>General Insurance Code of Practice</bold>, we advise that the key factors that affect premiums are the type and size of the risk,
      along with industry and claims experience
    </PremiumText>
    <Premium>
      <Limit>1,000.00</Limit>
      <BasePremium>90.00</BasePremium>
      <GST>9.00</GST>
      <StampDuty>7.51</StampDuty>
      <AdminCharge>15.00</AdminCharge>
      <GSTOnAdminCharge>1.00</GSTOnAdminCharge>
      <BrokerFee>0.00</BrokerFee>
      <GSTOnBrokerFee>0.00</GSTOnBrokerFee>
      <Total>1,951.51</Total>
    </Premium>
    <Premium>
      <Limit>2,000.00</Limit>
      <BasePremium>75.00</BasePremium>
      <GST>7.50</GST>
      <StampDuty>5.62</StampDuty>
      <AdminCharge>10.00</AdminCharge>
      <GSTOnAdminCharge>15.00</GSTOnAdminCharge>
      <BrokerFee>0.00</BrokerFee>
      <GSTOnBrokerFee>0.00</GSTOnBrokerFee>
      <Total>2,413.12</Total>
    </Premium>
  </Premiums>
  <Conditions>
    <Condition>
      <ConditionNumber>1</ConditionNumber>
      <ConditionText>Once this quote expires and if you wish to place cover we may request a new proposal form, renewal declaration or no claims declaration and also  reserve the right to amend the quotation terms and conditions. Alternatively please obtain a new quotation via the Webrater should the risk be suitable.</ConditionText>
    </Condition>
    <Condition>
      <ConditionNumber>2</ConditionNumber>
      <ConditionText>In the event that the proposed insured becomes aware of a material change to the nature of the risk to be insured, or a claim, or facts or circumstances which may lead to a claim between the date of the application and the inception of the proposed insurance, we reserve our rights to amend or withdraw our terms.</ConditionText>
    </Condition>
    <Condition>
      <ConditionNumber>3</ConditionNumber>
      <ConditionText>This quotation together with any material submitted by you will be the basis of a contract should cover be bound by the Insurer and shall be deemed to be attached to and form part of the policy.</ConditionText>
    </Condition>
    <Condition>
      <ConditionNumber>4</ConditionNumber>
      <ConditionText>Credit terms are <bold>90 days</bold> payment from the date of inception of the policy.</ConditionText>
    </Condition>
  </Conditions>
  <OptionalExtensions>
    <EmptyOptionalExtensions>
      No optional extension to apply <bold>unless otherwise shown below</bold>
    </EmptyOptionalExtensions>
  </OptionalExtensions>
</root>

我试过,应用非常通用的模板(参见上一个转换),但没有运气

    <?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:fo="http://www.w3.org/1999/XSL/Format">
  <xsl:include href="../../Common.xslt"/>
  <xsl:output indent="yes" />
  <xsl:output method="text" />
  <xsl:template match="root">
    <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" font-size="10pt">
      <fo:layout-master-set>
        <fo:simple-page-master master-name="all-pages" page-height="29.7cm" page-width="21cm">
          <fo:region-body region-name="xsl-region-body" margin-top="2.4cm" margin-bottom="2.1cm" margin-left="1cm" margin-right="1cm" border="1pt solid black" />
          <fo:region-before region-name="xsl-region-before" extent="2cm" margin-left="1cm" margin-right="1cm" />
          <fo:region-after region-name="xsl-region-after" extent="2.1cm" margin-left="1cm" margin-right="1cm" />
        </fo:simple-page-master>
      </fo:layout-master-set>
      <fo:page-sequence master-reference="all-pages">
        <fo:flow flow-name="xsl-region-body"  font-family="Arial" disable-output-escaping="yes">
          <fo:table table-layout="fixed"  margin-left="1cm" margin-right="1cm"  cell-spacing="1" width="17cm" padding-bottom="0.5em">
            <fo:table-column column-width="3.3cm"/>
            <fo:table-column column-width="13.7cm"/>
            <fo:table-body>
              <xsl:apply-templates select="QuoteNumber" />
              <xsl:apply-templates select="Insured" />
              <fo:table-row>
                <fo:table-cell padding="2pt">
                  <fo:block font-size="8pt" font-weight="bold"> LIMIT OF INDEMNITY  : </fo:block>
                </fo:table-cell>
                <fo:table-cell padding="2pt">
                  <fo:block font-size="8pt">
                    Any one Claim and in the aggregate during the insurance period:
                  </fo:block>
                </fo:table-cell>
              </fo:table-row>
              <fo:table-row>
                <fo:table-cell padding="2pt">
                </fo:table-cell>
                <fo:table-cell padding="2pt">
                  <fo:table margin="0pt">
                    <fo:table-body width="100%">
                      <fo:table-row>
                        <fo:table-cell padding="2pt">
                          <fo:block font-size="8pt">
                            (a)
                          </fo:block>
                        </fo:table-cell>
                        <fo:table-cell padding="2pt" width="0.2cm">
                        </fo:table-cell>
                        <fo:table-cell padding="2pt">
                          <fo:block font-size="8pt">
                            $ <xsl:value-of select="Limit1" />
                          </fo:block>
                        </fo:table-cell>
                      </fo:table-row>
                      <xsl:if test="Limit2">
                        <fo:table-row>
                          <fo:table-cell padding="2pt">
                            <fo:block font-size="8pt">
                              (b)
                            </fo:block>
                          </fo:table-cell>
                          <fo:table-cell padding="2pt" width="0.2cm">
                          </fo:table-cell>
                          <fo:table-cell padding="2pt">
                            <fo:block font-size="8pt">
                              $ <xsl:value-of select="Limit2" />
                            </fo:block>
                          </fo:table-cell>
                        </fo:table-row>
                      </xsl:if>
                      <xsl:if test="Limit3">
                        <fo:table-row>
                          <fo:table-cell padding="2pt">
                            <fo:block font-size="8pt">
                              (c)
                            </fo:block>
                          </fo:table-cell>
                          <fo:table-cell padding="2pt" width="0.2cm">
                          </fo:table-cell>
                          <fo:table-cell padding="2pt">
                            <fo:block font-size="8pt">
                              $ <xsl:value-of select="Limit3" />
                            </fo:block>
                          </fo:table-cell>
                        </fo:table-row>
                      </xsl:if>
                    </fo:table-body>
                  </fo:table>
                </fo:table-cell>
              </fo:table-row>
              <fo:table-row>
                <fo:table-cell padding="2pt">
                  <fo:block font-size="8pt" font-weight="bold">
                    PERIOD OF INSURANCE :
                  </fo:block>
                </fo:table-cell>
                <fo:table-cell padding="2pt">
                  <fo:table>
                    <fo:table-body>
                      <fo:table-row>
                        <fo:table-cell   padding-right="2pt" text-align="left" width="20%">
                          <fo:block font-size="8pt" > From: </fo:block>
                        </fo:table-cell>
                        <fo:table-cell  padding-right="2pt"  text-align="left" width="35%">
                          <fo:block font-size="8pt"  >
                            <xsl:value-of select="InsurancePeriodFrom" />
                          </fo:block>
                        </fo:table-cell>
                        <fo:table-cell padding-left="8pt"   padding-right="2pt"  text-align="left" width="10%">
                          <fo:block font-size="8pt" > To: </fo:block>
                        </fo:table-cell>
                        <fo:table-cell text-align="left" width="35%">
                          <fo:block font-size="8pt"  >
                            <xsl:value-of select="InsurancePeriodTo" />
                          </fo:block>
                        </fo:table-cell>
                      </fo:table-row>
                    </fo:table-body>
                  </fo:table>
                </fo:table-cell>
              </fo:table-row>
              <xsl:apply-templates select="Premiums" />
              <fo:table-row>
                <fo:table-cell padding="2pt" number-columns-spanned="2">
                  <fo:block font-size="8pt" padding-top="2pt"  font-weight="bold"> Schedule of Benefits: </fo:block>
                </fo:table-cell>
              </fo:table-row>
              <xsl:apply-templates select="OptionalExtensions" />
              <xsl:apply-templates select="ProposalDate" />
              <xsl:apply-templates select="ValidUntil" />
              <xsl:apply-templates select="PolicyWording" />
              <xsl:apply-templates select="Insurer" />
              <xsl:apply-templates select="Conditions" />
              <fo:table-row>
                <fo:table-cell padding="2pt" number-columns-spanned="2">
                  <fo:block font-size="8pt">
                    We trust this is in order, if you wish to discuss any part of this quote please do not hesitate to contact us.
                  </fo:block>
                </fo:table-cell>
              </fo:table-row>
              <xsl:apply-templates select="Date" />
            </fo:table-body>
          </fo:table>
        </fo:flow>
      </fo:page-sequence>
    </fo:root>
  </xsl:template>
  <xsl:template match="QuoteNumber">
    <fo:table-row>
      <fo:table-cell padding="2pt">
        <fo:block font-size="8pt" font-weight="bold"> QUOTATION NUMBER : </fo:block>
      </fo:table-cell>
      <fo:table-cell padding="2pt">
        <fo:block font-size="8pt">
          <xsl:value-of select="." />
        </fo:block>
      </fo:table-cell>
    </fo:table-row>
  </xsl:template>
  <xsl:template match="Insured">
    <fo:table-row>
      <fo:table-cell padding="2pt">
        <fo:block font-size="8pt" font-weight="bold"> INSURED : </fo:block>
      </fo:table-cell>
      <fo:table-cell padding="2pt" >
        <fo:block font-size="8pt" linefeed-treatment="preserve" font-weight="bold" wrap-option="wrap" hyphenate="true">
          <xsl:value-of select="." />
        </fo:block>
      </fo:table-cell>
    </fo:table-row>
  </xsl:template>
  <xsl:template match="Premiums">
    <fo:table-row>
      <fo:table-cell padding="2pt">
        <fo:block font-size="8pt" padding-top="2pt"  font-weight="bold"> PREMIUMS : </fo:block>
      </fo:table-cell>
      <fo:table-cell padding="2pt">
        <xsl:if test="PremiumText != ''">
          <xsl:apply-templates select="PremiumText" />
        </xsl:if>
        <xsl:apply-templates select="Premium" />
      </fo:table-cell>
    </fo:table-row>
  </xsl:template>
  <xsl:template match="PremiumText">
    <fo:table margin="0pt" width="100%">
      <fo:table-body  >
        <fo:table-row>
          <fo:table-cell font-size="8pt" padding-top="2pt" number-columns-spanned="3">
            <xsl:value-of select="." />
          </fo:table-cell>
        </fo:table-row>
      </fo:table-body>
    </fo:table>
  </xsl:template>
  <xsl:template match="Premium">
    <fo:table margin="0pt" width="10cm">
      <fo:table-body  >
        <fo:table-row>
          <fo:table-cell padding="2pt" width="2cm">
            <fo:block font-size="8pt" font-weight="bold">
              $<xsl:value-of select="Limit" />
            </fo:block>
          </fo:table-cell>
          <fo:table-cell padding="2pt" width="0.2cm">
          </fo:table-cell>
          <fo:table-cell padding="2pt">
            <fo:table margin="1pt 1pt 1pt 1pt" width="8cm">
              <fo:table-body >
                <fo:table-row border="0.5pt solid black">
                  <fo:table-cell padding="2pt" >
                    <fo:block font-size="8pt" text-align="left"> $ </fo:block>
                  </fo:table-cell>
                  <fo:table-cell padding="2pt">
                    <fo:block font-size="8pt" text-align="right">
                      <xsl:value-of select="BasePremium" />
                    </fo:block>
                  </fo:table-cell>
                  <fo:table-cell padding="2pt" width="0.2cm" border-right-color="black" border-right-style="solid" border-right-width="0.5pt" >
                  </fo:table-cell>
                  <fo:table-cell padding="2pt">
                    <fo:block font-size="8pt">   Base Premium</fo:block>
                  </fo:table-cell>
                </fo:table-row>
                <fo:table-row border="0.5pt solid black">
                  <fo:table-cell padding="2pt" >
                    <fo:block font-size="8pt" text-align="left"> $ </fo:block>
                  </fo:table-cell>
                  <fo:table-cell padding="2pt">
                    <fo:block font-size="8pt" text-align="right">
                      <xsl:value-of select="GST" />
                    </fo:block>
                  </fo:table-cell>
                  <fo:table-cell padding="2pt" width="0.2cm" border-right-color="black" border-right-style="solid" border-right-width="0.5pt" >
                  </fo:table-cell>
                  <fo:table-cell padding="2pt">
                    <fo:block font-size="8pt">   GST</fo:block>
                  </fo:table-cell>
                </fo:table-row>
                <xsl:if test="../../Region='AUS'">
                  <fo:table-row border="0.5pt solid black">
                    <fo:table-cell padding="2pt" >
                      <fo:block font-size="8pt" text-align="left"> $ </fo:block>
                    </fo:table-cell>
                    <fo:table-cell padding="2pt">
                      <fo:block font-size="8pt" text-align="right">
                        <xsl:value-of select="StampDuty" />
                      </fo:block>
                    </fo:table-cell>
                    <fo:table-cell padding="2pt" width="0.2cm" border-right-color="black" border-right-style="solid" border-right-width="0.5pt" >
                    </fo:table-cell>
                    <fo:table-cell padding="2pt">
                      <fo:block font-size="8pt">   Stamp Duty</fo:block>
                    </fo:table-cell>
                  </fo:table-row>
                </xsl:if>
                <xsl:if test="../../Region='AUS'">
                  <fo:table-row border="0.5pt solid black">
                    <fo:table-cell padding="2pt" >
                      <fo:block font-size="8pt" text-align="left"> $ </fo:block>
                    </fo:table-cell>
                    <fo:table-cell padding="2pt">
                      <fo:block font-size="8pt" text-align="right">
                        <xsl:value-of select="AdminCharge" />
                      </fo:block>
                    </fo:table-cell>
                    <fo:table-cell padding="2pt" width="0.2cm" border-right-color="black" border-right-style="solid" border-right-width="0.5pt" >
                    </fo:table-cell>
                    <fo:table-cell padding="2pt">
                      <fo:block font-size="8pt">
                        Service Fee
                      </fo:block>
                    </fo:table-cell>
                  </fo:table-row>
                  <fo:table-row border="0.5pt solid black">
                    <fo:table-cell padding="2pt" >
                      <fo:block font-size="8pt" text-align="left"> $ </fo:block>
                    </fo:table-cell>
                    <fo:table-cell padding="2pt">
                      <fo:block font-size="8pt" text-align="right">
                        <xsl:value-of select="GSTOnAdminCharge" />
                      </fo:block>
                    </fo:table-cell>
                    <fo:table-cell padding="2pt" width="0.2cm" border-right-color="black" border-right-style="solid" border-right-width="0.5pt" >
                    </fo:table-cell>
                    <fo:table-cell padding="2pt">
                      <fo:block font-size="8pt">
                        GST On Service Fee
                      </fo:block>
                    </fo:table-cell>
                  </fo:table-row>
                </xsl:if>
                <xsl:if test="ContractReviewInGST">
                  <fo:table-row border="0.5pt solid black">
                    <fo:table-cell padding="2pt" >
                      <fo:block font-size="8pt" text-align="left"> $ </fo:block>
                    </fo:table-cell>
                    <fo:table-cell padding="2pt">
                      <fo:block font-size="8pt" text-align="right">
                        <xsl:value-of select="ContractReviewInGST" />
                      </fo:block>
                    </fo:table-cell>
                    <fo:table-cell padding="2pt" width="0.2cm" border-right-color="black" border-right-style="solid" border-right-width="0.5pt" >
                    </fo:table-cell>
                    <fo:table-cell padding="2pt">
                      <fo:block font-size="8pt">   Contract Review (inc GST)</fo:block>
                    </fo:table-cell>
                  </fo:table-row>
                </xsl:if>
                <fo:table-row border="0.5pt solid black">
                  <fo:table-cell padding="2pt" >
                    <fo:block font-size="8pt" text-align="left"> $ </fo:block>
                  </fo:table-cell>
                  <fo:table-cell padding="2pt">
                    <fo:block font-size="8pt" text-align="right">
                      <xsl:value-of select="BrokerFee" />
                    </fo:block>
                  </fo:table-cell>
                  <fo:table-cell padding="2pt" width="0.2cm" border-right-color="black" border-right-style="solid" border-right-width="0.5pt" >
                  </fo:table-cell>
                  <fo:table-cell padding="2pt">
                    <fo:block font-size="8pt">   Broker Fee</fo:block>
                  </fo:table-cell>
                </fo:table-row>
                <fo:table-row border="0.5pt solid black">
                  <fo:table-cell padding="2pt" >
                    <fo:block font-size="8pt" text-align="left"> $ </fo:block>
                  </fo:table-cell>
                  <fo:table-cell padding="2pt">
                    <fo:block font-size="8pt" text-align="right">
                      <xsl:value-of select="GSTOnBrokerFee" />
                    </fo:block>
                  </fo:table-cell>
                  <fo:table-cell padding="2pt" width="0.2cm" border-right-color="black" border-right-style="solid" border-right-width="0.5pt" >
                  </fo:table-cell>
                  <fo:table-cell padding="2pt">
                    <fo:block font-size="8pt">   GST On Broker Fee</fo:block>
                  </fo:table-cell>
                </fo:table-row>
                <fo:table-row border="0.5pt solid black">
                  <fo:table-cell padding="2pt" >
                    <fo:block font-size="8pt" text-align="left"> $ </fo:block>
                  </fo:table-cell>
                  <fo:table-cell padding="2pt">
                    <fo:block font-size="8pt" text-align="right">
                      <xsl:value-of select="Total" />
                    </fo:block>
                  </fo:table-cell>
                  <fo:table-cell padding="2pt" width="0.2cm" border-right-color="black" border-right-style="solid" border-right-width="0.5pt" >
                  </fo:table-cell>
                  <fo:table-cell padding="2pt">
                    <fo:block font-size="8pt">   TOTAL</fo:block>
                  </fo:table-cell>
                </fo:table-row>
                <xsl:if test="AlternativeTotal">
                  <fo:table-row border="0.5pt solid black">
                    <fo:table-cell padding="2pt" >
                      <fo:block font-size="8pt" text-align="left"> $ </fo:block>
                    </fo:table-cell>
                    <fo:table-cell padding="2pt">
                      <fo:block font-size="8pt" text-align="right">
                        <xsl:value-of select="AlternativeTotal" />
                      </fo:block>
                    </fo:table-cell>
                    <fo:table-cell padding="2pt" width="0.2cm" border-right-color="black" border-right-style="solid" border-right-width="0.5pt" >
                    </fo:table-cell>
                    <fo:table-cell padding="2pt">
                      <fo:block font-size="8pt">   Alternative Grand Total</fo:block>
                    </fo:table-cell>
                  </fo:table-row>
                </xsl:if>
              </fo:table-body>
            </fo:table>
          </fo:table-cell>
        </fo:table-row>
      </fo:table-body>
    </fo:table>
  </xsl:template>
  <xsl:template match="Conditions">
    <xsl:if test="count(Condition)>0 ">
      <fo:table-row >
        <fo:table-cell padding="2pt" number-columns-spanned="2">
          <fo:block font-size="8pt" font-weight="bold" keep-with-next.within-page="always"> Conditions </fo:block>
        </fo:table-cell>
      </fo:table-row>

      <fo:table-row >
        <fo:table-cell padding="2pt" number-columns-spanned="2">
          <fo:list-block>

            <fo:list-item>
              <fo:list-item-label>  </fo:list-item-label>
            </fo:list-item>

            <xsl:apply-templates select="Condition" />

          </fo:list-block>
        </fo:table-cell>
      </fo:table-row>
    </xsl:if>
  </xsl:template>
  <xsl:template match="Condition">
    <fo:list-item>
      <fo:list-item-label>
        <fo:block font-size="8pt">
          <xsl:value-of select="ConditionNumber" />.
        </fo:block>

      </fo:list-item-label>
      <fo:list-item-body>
        <fo:block font-size="8pt">
          <xsl:value-of select="ConditionText" />
        </fo:block>
      </fo:list-item-body>
    </fo:list-item>
  </xsl:template>
  <xsl:template match="ProposalDate">
    <fo:table-row>
      <fo:table-cell padding="2pt">
        <fo:block font-size="8pt" font-weight="bold"> DATE OF PROPOSAL : </fo:block>
      </fo:table-cell>
      <fo:table-cell padding="2pt">
        <fo:block font-size="8pt">
          <xsl:value-of select="." />
        </fo:block>
      </fo:table-cell>
    </fo:table-row>
  </xsl:template>
  <xsl:template match="ValidUntil">
    <fo:table-row>
      <fo:table-cell padding="2pt">
        <fo:block font-size="8pt" font-weight="bold"> QUOTE VALID UNTIL : </fo:block>
      </fo:table-cell>
      <fo:table-cell padding="2pt">
        <fo:block font-size="8pt">
          <xsl:value-of select="." />
        </fo:block>
      </fo:table-cell>
    </fo:table-row>
  </xsl:template>
  <xsl:template match="PolicyWording">
    <fo:table-row>
      <fo:table-cell padding="2pt">
        <fo:block font-size="8pt" font-weight="bold"> POLICY WORDING : </fo:block>
      </fo:table-cell>
      <fo:table-cell padding="2pt">
        <fo:block font-size="8pt">
          <xsl:value-of select="." />
        </fo:block>
      </fo:table-cell>
    </fo:table-row>
  </xsl:template>
  <xsl:template match="Insurer">
    <fo:table-row>
      <fo:table-cell padding="2pt">
        <fo:block font-size="8pt" font-weight="bold"> INSURER : </fo:block>
      </fo:table-cell>
      <fo:table-cell padding="2pt">
        <fo:block font-size="8pt">
          <xsl:value-of select="." />
        </fo:block>
      </fo:table-cell>
    </fo:table-row>
  </xsl:template>
  <xsl:template match="Date">
    <fo:table-row>
      <fo:table-cell padding="2pt">
        <fo:block font-size="8pt" font-weight="bold"> DATE : </fo:block>
      </fo:table-cell>
      <fo:table-cell padding="2pt">
        <fo:block font-size="8pt">
          <xsl:value-of select="." />
        </fo:block>
      </fo:table-cell>
    </fo:table-row>
  </xsl:template>
  <xsl:template match="bold">
    <fo:block font-size="8pt" font-weight="bold">
      <xsl:copy-of select="/"/>
    </fo:block>
  </xsl:template>

</xsl:stylesheet>

提前感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

我们没有办法在没有看到你的XSLT的其余部分(MCVE)的情况下给出具体的答案,但是发生的事情是bold元素永远不会得到处理。

您需要确保在可能覆盖的任何祖先级别应用模板(xsl:apply-templates)。另外,了解built-in templates工作将如何发挥作用。

这是一个如何看待它的例子。

XML输入

<root>
    <first><inner>This is 1. <bold>important</bold>, so what</inner></first>
    <first><inner>This is 2. <bold>important</bold>, so what what</inner></first>
    <second><inner2>This is 3. <bold>important</bold>, so what</inner2></second>
    <third><inner3>This is 4. <bold>important</bold>, so what</inner3></third>
</root>

XSLT 1.0

<xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:fo="http://www.w3.org/1999/XSL/Format">
    <xsl:output indent="yes"/>
    <xsl:strip-space elements="*"/>

    <xsl:template match="/*">
        <fo:root>
            <fo:layout-master-set>
                <fo:simple-page-master master-name="my-page" 
                    page-width="8.5in" 
                    page-height="11in">
                    <fo:region-body margin="1in" 
                        margin-top="1.5in" 
                        margin-bottom="1.5in"/>
                </fo:simple-page-master>
            </fo:layout-master-set>
            <fo:page-sequence master-reference="my-page">
                <fo:flow flow-name="xsl-region-body"> 
                    <xsl:apply-templates/>
                </fo:flow>
            </fo:page-sequence>
        </fo:root>
    </xsl:template>

    <xsl:template match="inner|inner2|inner3">
        <fo:block>
            <xsl:apply-templates/>
        </fo:block>
    </xsl:template>

    <xsl:template match="bold">
        <fo:inline font-weight="bold">
            <xsl:apply-templates/>
        </fo:inline>
    </xsl:template>

</xsl:stylesheet>

XSL-FO输出

<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
   <fo:layout-master-set>
      <fo:simple-page-master master-name="my-page" page-width="8.5in" page-height="11in">
         <fo:region-body margin="1in" margin-top="1.5in" margin-bottom="1.5in"/>
      </fo:simple-page-master>
   </fo:layout-master-set>
   <fo:page-sequence master-reference="my-page">
      <fo:flow flow-name="xsl-region-body">
         <fo:block>This is 1. <fo:inline font-weight="bold">important</fo:inline>, so what</fo:block>
         <fo:block>This is 2. <fo:inline font-weight="bold">important</fo:inline>, so what what</fo:block>
         <fo:block>This is 3. <fo:inline font-weight="bold">important</fo:inline>, so what</fo:block>
         <fo:block>This is 4. <fo:inline font-weight="bold">important</fo:inline>, so what</fo:block>
      </fo:flow>
   </fo:page-sequence>
</fo:root>

渲染PDF输出(使用FOP 1.1)

Rendered PDF Output