【发布时间】:2019-05-09 08:00:44
【问题描述】:
如何获取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'
【问题讨论】:
-
问题是什么?如何查询 XML?或者如何编写 XSLT 转换?在第二种情况下,为什么要发布 SQL 查询?
-
@PanagiotisKanavos 我想使用 xslt 获取 AMEX、AMEX 的值。我已经发布了 sql 查询来解释我如何使用东西获得 amex amex 值。
-
这与问题无关,只会引起混乱。即使谈论 STUFF 也是错误的——东西并没有连接任何东西。您发布的是 XML 路径字符串连接查询。您可以(应该)删除对 SQL Server 和标记的 任何 引用,仍然得到相同的答案。
-
至于
i want to fetch the value of AMEX,AMEX using xsltXSLT 是一种转换 语言。它需要一个 XML 文档并生成另一个。它使用 XPath 来选择值,Michael 发布了将选择所需值的 sn-p。你想要什么作为 输出? -
您发布的
desired output是迈克尔的回答所提供的。然而你在那里说你想要<Payment>AMEX, AMEX</Payment>,不只是AMEX, AMEX