如果使用自定义命名空间,如何执行xsl转换

时间:2016-11-08 21:34:36

标签: xml xslt

源xml包含自定义命名空间:

<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
  <soapenv:Body>
    <ns:getBuyInvoiceResponse xmlns:ns="http://iws.itella.ee">
      <ns:return>
        <E_Invoice xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
...

XSL还包含那些命名空间:

<?xml version="1.0" encoding="ISO-8859-1" standalone="no" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns="http://iws.itella.ee"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"

它们用于选择器

  <xsl:template match="/soapenv:Envelope/soapenv:Body/ns:getBuyInvoiceResponse/E_Invoice/Invoice/InvoiceItem/InvoiceItemGroup/*">

使用http://www.utilities-online.info/xsltransformation进行XSLT转换会创建空文档。如何解决这个问题,以便创建文档内容?

1 个答案:

答案 0 :(得分:1)

首先,E_Invoicens:return的孩子,而不是ns:getBuyInvoiceResponse - 所以你的第二个模板什么都不匹配。

另请注意,匹配模式选择表达式不同:您不需要拼出完整路径。这样:

<xsl:template match="InvoiceItemGroup/*">

也会起作用。

最后,请注意,如果必须计算元素的名称,则只需使用xsl:element。否则,使用文字结果元素会更短更好。