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個對這個問題的答案。 –