如何使用xslt 1.0获取主要元素值?

时间:2019-05-09 08:00:44

标签: xml xslt-1.0

如何获取Header主要元素“ AMEX,AMEX”的值? 下面是我的xml,其中包含标题和值AMEX,AMEX。我想获取“ AMEX,AMEX”值以在xsl:fo表单元格中显示它。

xml

<Documents>
 <Document>
<PackingNote>
  <Header>AMEX, AMEX<CustomerDetail>Adeel/000004</CustomerDetail><Despatchdate>09/05/2019</Despatchdate><OrderNumber>000534</OrderNumber><OrderNumberBatch>000534-1</OrderNumberBatch></Header>
  <Header>AMEX, AMEX<CustomerDetail>Adeel/000004</CustomerDetail><Despatchdate>09/05/2019</Despatchdate><OrderNumber>000534</OrderNumber><OrderNumberBatch>000534-2</OrderNumberBatch></Header>
  <Lines>
    <Line>
      <ProductName>Kid-Sweater-Winter Aqua</ProductName>
      <Quantity>1.00</Quantity>
      <Price>£15.00</Price>
      <Size>Small/Slim Fit</Size>
      <ReasonCode />
      <ReturnQty />
      <Fit>Fit </Fit>
    </Line>
  </Lines>
  <PackedBy>
    <SubTotal>£30</SubTotal>
    <Shipping>£2.00</Shipping>
    <Total>£32</Total>
  </PackedBy>
</PackingNote>
  </Document>
</Documents>

xslt

<xsl:template match="Header">
<!-- Title -->
<fo:table table-width="27.5cm" table-height="2cm">
  <fo:table-column column-width="5.5cm" />
  <fo:table-column column-width="3.5cm" />
  <fo:table-column column-width="14.5cm" />
  <fo:table-column column-width="4cm" />
  <fo:table-body>
    <fo:table-row border-width="0mm">
      <fo:table-cell>
        <fo:table table-layout="fixed">
          <fo:table-column column-width="5cm" />
          <fo:table-body>
            <fo:table-row />
          </fo:table-body>
        </fo:table>
      </fo:table-cell>
      <fo:table-cell>
        <fo:table table-layout="fixed" padding-top="1.2cm">
          <fo:table-column column-width="3.5cm" />
          <fo:table-body>
            <fo:table-row>
              <fo:table-cell>
                <fo:block text-align="center" padding-top="0.3cm">

                </fo:block>
              </fo:table-cell>
            </fo:table-row>
          </fo:table-body>
        </fo:table>
      </fo:table-cell>
      <fo:table-cell padding="1mm" border-width="0mm">
        <fo:table table-layout="auto" font-family="Calibri" table-width="14.5cm">
          <fo:table-column column-width="5.1cm" />
          <fo:table-column column-width="3.9cm" />
          <fo:table-column column-width="2.5cm" />
          <fo:table-column column-width="2.8cm" />
          <fo:table-header text-align="left" border-width="0mm">
            <fo:table-row height="2em" border="inherit" background-color="#D9D9D9" font-family="Arial">
              <fo:table-cell padding="1mm" padding-left="0.2cm" border-width="1px" border-style="solid">
                <fo:block font-size="11pt" text-align="left" >
                  <fo:inline>Customer Name/No</fo:inline>
                </fo:block>
              </fo:table-cell>
              <fo:table-cell padding="1mm" border-width="1px" border-style="solid">
                <fo:block font-size="11pt" text-align="left" >
                  <fo:inline>Payment Method</fo:inline>
                </fo:block>
              </fo:table-cell>
              <fo:table-cell padding="1mm" border-width="1px" border-style="solid">
                <fo:block font-size="11pt" text-align="center" >
                  <fo:inline>Despatch Date</fo:inline>
                </fo:block>
              </fo:table-cell>
              <fo:table-cell padding="1mm" border-width="1px" border-style="solid">
                <fo:block font-size="11pt" text-align="center" >
                  <fo:inline>Order No.</fo:inline>
                </fo:block>
              </fo:table-cell>
            </fo:table-row>
          </fo:table-header>
          <fo:table-body>
            <fo:table-row border-width="4px" border-style="solid" height="2em" font-family="Segoe UI">
              <fo:table-cell padding-bottom="0.5mm" padding-left="0.2cm" border-width="1px" border-style="solid">
                <fo:block font-size="11pt" text-align="left">
                  <xsl:value-of select="CustomerDetail" />
                </fo:block>
              </fo:table-cell>
              <fo:table-cell padding-left="0.1cm" padding-bottom="0.5mm" padding-right="0.5cm" border-width="1px" border-style="solid">
                <fo:block font-size="11pt" text-align="left">
       <xsl:value-of select="Header" />
    </fo:block>
              </fo:table-cell>
              <fo:table-cell padding-left="0.8mm" padding-bottom="0.5mm" padding-right="0.5cm" border-width="1px" border-style="solid">
                <fo:block font-size="11pt" text-align="center">
                  <xsl:value-of select="Despatchdate" />
                </fo:block>
              </fo:table-cell>
              <fo:table-cell padding-left="0.1cm" padding-bottom="0.5mm" padding-right="0.5cm" border-width="1px" border-style="solid">
                <fo:block font-size="11pt" text-align="center">
                  <xsl:value-of select="OrderNumber" />
                </fo:block>
              </fo:table-cell>
            </fo:table-row>
          </fo:table-body>
        </fo:table>
      </fo:table-cell>
      <fo:table-cell padding="1mm">
        <fo:table table-layout="fixed">
          <fo:table-column column-width="4cm" />
          <fo:table-body>
            <fo:table-row>
              <fo:table-cell>
                <fo:block text-align="center" padding-top="0.3cm">

                </fo:block>
              </fo:table-cell>
            </fo:table-row>
          </fo:table-body>
        </fo:table>
      </fo:table-cell>
    </fo:table-row>
  </fo:table-body>
</fo:table>

所需的输出

first header value 'AMEX,AMEX'

1 个答案:

答案 0 :(得分:1)

假设您处于PackingNote的上下文中,说明:

<xsl:value-of select="Header[1]/text()"/>

将返回:

AMEX, AMEX

如果您处于Header的上下文中,请使用:

<xsl:value-of select="text()"/>