xslt apply-templates 删除除了传递的值之外的所有内容

xslt apply-templates removes everything but values passed

我正在使用 XSLT 模板生成发送到呼叫中心的电子邮件。我遇到的问题 - apply-templates 中的转换消除了除值之外的所有内容。很可能这是我没有看到的微不足道的事情。

XSLT:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" indent="yes"/>

  <xsl:template match="/*">
    We have just received the following Legal Services Call me back form. Please contact them as soon as possible..<br /><br /><br />
    <table border="0px">
      <tr>
        <td>Product</td>
        <td width="10px">:</td>
        <td>
          <xsl:value-of select="ShortProductName"/>
        </td>
      </tr>
      <xsl:if test="HasSingleOrCouple='true'">
        <tr>
          <td>Single Or Couple</td>
          <td width="10px">:</td>
          <td>
            <xsl:value-of select="SingleOrCouple"/>
          </td>
        </tr>
      </xsl:if>
      <tr>
        <td>Title</td>
        <td width="10px">:</td>
        <td>
          <xsl:value-of select="Title"/>
        </td>
      </tr>
      <tr>
        <td>Firstname</td>
        <td width="10px">:</td>
        <td>
          <xsl:value-of select="Firstname"/>
        </td>
      </tr>
      <tr>
        <td>Surname</td>
        <td width="10px">:</td>
        <td>
          <xsl:value-of select="Surname"/>
        </td>
      </tr>
      <tr>
        <td>Telephone</td>
        <td width="10px">:</td>
        <td>
          <xsl:value-of select="Phone"/>
        </td>
      </tr>
      <xsl:apply-templates select="Products/ProductsItem"></xsl:apply-templates>
    </table>
  </xsl:template>

  <xsl:template name="Products">
      <tr>
        <td>
          Product
        </td>
        <td width="10px">:</td>
        <td>
          <xsl:value-of select="ProductType"/>
        </td>
      </tr>
      <xsl:apply-templates select="PriceLines/PriceLinesItem" />
  </xsl:template>

  <xsl:template match="PriceLine">
      <tr>
        <td>
          <xsl:value-of select="Key"/>
        </td>
        <td width="10px">:</td>
        <td>
          <xsl:value-of select="format-number(Value, '#,##0.00')"/>
        </td>
      </tr>
  </xsl:template>
</xsl:stylesheet> 

XML:

<?xml version="1.0" encoding="utf-8" ?>
<object>
    <HasSingleOrCouple>false</HasSingleOrCouple>
    <Title>Mrs</Title>
    <Firstname>M</Firstname>
    <Surname>Vaitke</Surname>
    <Phone>07809263588</Phone>
    <Products>
        <ProductsItem>
            <ProductType>Sale quotation</ProductType>
            <PriceLines>
                <PriceLinesItem>
                    <Key>Legal fee</Key>
                    <Value>540.8300</Value>
                </PriceLinesItem>
                <PriceLinesItem>
                    <Key>legal discount</Key>
                    <Value>0</Value>
                </PriceLinesItem>
                <PriceLinesItem>
                    <Key>Leasehold fee</Key>
                    <Value>125.0000</Value>
                </PriceLinesItem>
                <PriceLinesItem>
                    <Key>Total legal fees (excluding VAT)</Key>
                    <Value>665.8300</Value>
                </PriceLinesItem>
                <PriceLinesItem>
                    <Key>Anti money laundering (AML) checks</Key>
                    <Value>6.0000</Value>
            </PriceLinesItem>
            <PriceLinesItem>
                <Key>Lender liaison fee</Key>
                <Value>0</Value>
            </PriceLinesItem>
            <PriceLinesItem>
                <Key>Bank transfer fee</Key>
                <Value>30.0000</Value>
            </PriceLinesItem>
            <PriceLinesItem>
                <Key>Office copies</Key>
                <Value>12.0000</Value>
            </PriceLinesItem>
            <PriceLinesItem>
                <Key>Total other fees (excluding VAT)</Key>
                <Value>48.0000</Value>
            </PriceLinesItem>
            <PriceLinesItem>
                <Key>Total VAT</Key>
                <Value>142.76600</Value>
            </PriceLinesItem>
            <PriceLinesItem>
                <Key>Total (including VAT)</Key>
                <Value>856.59600</Value>
            </PriceLinesItem>
            </PriceLines>
        </ProductsItem>
    </Products>
    <IsCouple>false</IsCouple>
    <Product>Conveyancing Service</Product>
    <ShortProductName>Conveyancing</ShortProductName>
    <AdditionalPriceLines>
        <AdditionalPriceLinesItem>
            <Key>Total</Key>
            <Value>856.59600</Value>
        </AdditionalPriceLinesItem>
    </AdditionalPriceLines>
</object>

我得到的结果:

<?xml version="1.0" encoding="UTF-8"?>
    We have just received the following Legal Services Call me back form. Please contact them as soon as possible..<br/>
<br/>
<br/>
<table border="0px">
   <tr>
      <td>Product</td>
      <td width="10px">:</td>
      <td>Conveyancing</td>
   </tr>
   <tr>
      <td>Title</td>
      <td width="10px">:</td>
      <td>Mrs</td>
   </tr>
   <tr>
      <td>Firstname</td>
      <td width="10px">:</td>
      <td>M</td>
   </tr>
   <tr>
      <td>Surname</td>
      <td width="10px">:</td>
      <td>Vaitke</td>
   </tr>
   <tr>
      <td>Telephone</td>
      <td width="10px">:</td>
      <td>07809263588</td>
   </tr>
            Sale quotation


                    Legal fee
                    540.8300


                    legal discount
                    0


                    Leasehold fee
                    125.0000


                    Total legal fees (excluding VAT)
                    665.8300


                    Anti money laundering (AML) checks
                    6.0000


                Lender liaison fee
                0


                Bank transfer fee
                30.0000


                Office copies
                12.0000


                Total other fees (excluding VAT)
                48.0000


                Total VAT
                142.76600


                Total (including VAT)
                856.59600


        </table>

如何保留 html 标签?

如果我猜对了,你需要修改:

<xsl:template name="Products">

至:

<xsl:template match="ProductsItem">

(注意从 namematch 的变化!)

和:

<xsl:template match="PriceLine">

至:

<xsl:template match="PriceLinesItem">