【问题标题】:avoid namespace withing xslt避免使用 xslt 命名空间
【发布时间】:2016-02-18 22:02:16
【问题描述】:

我试图避免(为了创建一个新的 HTML 文件)来自我的输入文件的命名空间。 我的 xslt 文件如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 exclude-result-prefixes="import_lc_iss">
<xsl:template match="/">
  <html>
  <body>
    <h2>Recieved Message </h2>
    <table border="1">
       <tr >
        <th>Entity</th>
        <th>Reference Number</th>
        <th>Transaction Date</th>
      </tr>
        <tr>
           <td><xsl:value-of select="/header/entity"/></td>
           <td><xsl:value-of select="/header/reference_no"/></td>
           <td><xsl:value-of select="/header/transaction_date"/></td>
        </tr>
    </table>
  </body>
  </html>
</xsl:template>

</xsl:stylesheet>

我的 xml 输入如下所示:

  <?xml version="1.0" encoding="UTF-8"?>
    <import_lc_iss xmlns="interface.nicom.allnett">
    <header direction="Outgoing" send_date="2015-09-10T19:25:24+03:00">
    <entity>001</entity>
    <customer id="11111111-1"/>
    <deal_no/>
    <identity deal_type="01" step="ISS" step_no="0"/>
    <reference_no>LCI00000000042</reference_no>
    <transaction_date>2015-09-10T19:25:14+03:00</transaction_date>
    </header>
    </import_lc_iss> 

为了检索实体标签内的内容。我正在尝试跳过 nsame 空间。我尝试添加到样式表中

exclude-result-prefixes="import_lc_iss"

但它没有工作。 有没有办法获取这些值?

提前致谢

【问题讨论】:

标签: java xml xslt


【解决方案1】:

命名空间将被使用,而不是被避免。而exclude-result-prefixes 不能那样工作。试试:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns1="interface.nicom.allnett"
exclude-result-prefixes="ns1">

<xsl:template match="/ns1:import_lc_iss">
  <html>
  <body>
    <h2>Recieved Message </h2>
    <table border="1">
       <tr >
        <th>Entity</th>
        <th>Reference Number</th>
        <th>Transaction Date</th>
      </tr>
        <tr>
           <td><xsl:value-of select="ns1:header/ns1:entity"/></td>
           <td><xsl:value-of select="ns1:header/ns1:reference_no"/></td>
           <td><xsl:value-of select="ns1:header/ns1:transaction_date"/></td>
        </tr>
    </table>
  </body>
  </html>
</xsl:template>

</xsl:stylesheet>

【讨论】:

    猜你喜欢
    • 2011-08-16
    • 1970-01-01
    • 1970-01-01
    • 2019-05-11
    • 2012-03-29
    • 1970-01-01
    • 2020-05-13
    • 1970-01-01
    • 2017-07-04
    相关资源
    最近更新 更多