0
这是我第一次使用.xsl,所以应该是一个简单的问题。用XSL转换XML会产生纯文本输出
我有这样的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>
而且我有这个的.xsl
<?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">
<xsl:output method="xml" encoding="UTF-8" indent="yes"/>
<xsl:template match="PublishTESTWS1ASSET/TESTWS1ASSETSet">
<xsl:apply-templates select="ASSET"/>
</xsl:template>
<xsl:template match="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="DESCRIPTION"/></name>
<number><xsl:value-of select="ASSETID"/></number>
</tes:addAsset>
</soapenv:Body>
</soapenv:Envelope>
</xsl:template>
</xsl:stylesheet>
当这个被改造它提出了以纯文本以下
52
1001
Fire Extinguisher
我已经将其缩小到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文档
搜索“XSLT默认命名空间”,您会发现574个对这个问题的答案。 –