Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用XSL转换XML生成纯文本输出_Xml_Xslt_Maximo - Fatal编程技术网

使用XSL转换XML生成纯文本输出

使用XSL转换XML生成纯文本输出,xml,xslt,maximo,Xml,Xslt,Maximo,这是我第一次使用.xsl,所以应该是一个简单的问题 我有这个xml <?xml version="1.0" encoding="UTF-8"?> <PublishTESTWS1ASSET xmlns="http://www.ibm.com/maximo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" creationDateTime="2017-01-22T20:07:28-08:00" transLanguage=

这是我第一次使用.xsl,所以应该是一个简单的问题

我有这个xml

<?xml version="1.0" encoding="UTF-8"?>
<PublishTESTWS1ASSET xmlns="http://www.ibm.com/maximo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" creationDateTime="2017-01-22T20:07:28-08:00" transLanguage="EN" baseLanguage="EN" messageID="3649776.1485144448726917270" maximoVersion="7 6 20141117-2230 V7600-218" event="0">
   <TESTWS1ASSETSet>
      <ASSET>
         <ASSETID>52</ASSETID>
         <ASSETNUM>1001</ASSETNUM>
         <DESCRIPTION>Fire Extinguisher</DESCRIPTION>
      </ASSET>
   </TESTWS1ASSETSet>
</PublishTESTWS1ASSET>
我已将其缩小到PublishTESTWS1ASSET中的属性

xmlns="http://www.ibm.com/maximo"
删除生成正确输出的

  <soapenv:Envelope 
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
                  xmlns:tes="http://testws1/"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soapenv:Header/>
   <soapenv:Body>
      <tes:addAsset>
         <name>Fire Extinguisher</name>
         <number>52</number>
      </tes:addAsset>
   </soapenv:Body>
</soapenv:Envelope>

有人能告诉我为什么会发生这种情况,以及如何在不更改原始xml文档的情况下修复它吗;没有这一点,您编写的模板将与输入XML的元素不匹配。您获得一些输出的原因是有内置的模板来处理您的输入XML

您需要在XSLT中声明名称空间和前缀(可选),并使用它们来匹配元素。 请参考以下代码:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tes="http://testws1/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns="http://www.ibm.com/maximo">
   <xsl:output method="xml" encoding="UTF-8" indent="yes"/>
   <xsl:template match="ns:PublishTESTWS1ASSET/ns:TESTWS1ASSETSet">
      <xsl:apply-templates select="ns:ASSET"/>
   </xsl:template>
   <xsl:template match="ns:ASSET">
         <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tes="http://testws1/">
         <soapenv:Header/>
         <soapenv:Body>
            <tes:addAsset>
                <name><xsl:value-of select="ns:DESCRIPTION"/></name>
               <number><xsl:value-of select="ns:ASSETID"/></number>
            </tes:addAsset>
       </soapenv:Body>
      </soapenv:Envelope>
   </xsl:template>
</xsl:stylesheet>

在上面的XSLT中,名称空间http://www.ibm.com/maximo 使用前缀ns声明。在其余的XPath中,为了匹配元素,使用了相同的前缀。

搜索XSLT默认名称空间,您将找到574个相同问题的答案。
  <soapenv:Envelope 
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
                  xmlns:tes="http://testws1/"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soapenv:Header/>
   <soapenv:Body>
      <tes:addAsset>
         <name>Fire Extinguisher</name>
         <number>52</number>
      </tes:addAsset>
   </soapenv:Body>
</soapenv:Envelope>
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tes="http://testws1/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns="http://www.ibm.com/maximo">
   <xsl:output method="xml" encoding="UTF-8" indent="yes"/>
   <xsl:template match="ns:PublishTESTWS1ASSET/ns:TESTWS1ASSETSet">
      <xsl:apply-templates select="ns:ASSET"/>
   </xsl:template>
   <xsl:template match="ns:ASSET">
         <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tes="http://testws1/">
         <soapenv:Header/>
         <soapenv:Body>
            <tes:addAsset>
                <name><xsl:value-of select="ns:DESCRIPTION"/></name>
               <number><xsl:value-of select="ns:ASSETID"/></number>
            </tes:addAsset>
       </soapenv:Body>
      </soapenv:Envelope>
   </xsl:template>
</xsl:stylesheet>