元素中 XML 命名空间的错误输出
Wrong output on XML namespace in element
我最近问了一个关于 XML 输出错误的问题,原来是因为命名空间被放入了一个元素。
现在我进一步研究了这一点,不幸的是我仍然卡在输出上,因为我不知道现在要给前缀什么。
希望你能帮助我。
下面是我现在拥有的文件和我想要的输出。
我的输入XML:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<ns2:readAllAMDResV04 xmlns:ns2="http://main.jws.com.hanel.de">
<ns2:return>
<article xmlns="http://main.jws.com.hanel.de/xsd">
<articleNumber>Aadrapot99900</articleNumber>
<articleName/>
<inventoryAtStorageLocation>2</inventoryAtStorageLocation>
</article>
<article xmlns="http://main.jws.com.hanel.de/xsd">
<articleNumber>Aadrapot99900</articleNumber>
<articleName/>
<inventoryAtStorageLocation>7</inventoryAtStorageLocation>
</article>
<article xmlns="http://main.jws.com.hanel.de/xsd">
<articleNumber>Ae13963</articleNumber>
<articleName/>
<inventoryAtStorageLocation>128</inventoryAtStorageLocation>
</article>
<article xmlns="http://main.jws.com.hanel.de/xsd">
<articleNumber>PCM11512050E</articleNumber>
<articleName/>
<inventoryAtStorageLocation>68</inventoryAtStorageLocation>
</article>
<ns1:returnValue xmlns:ns1="http://main.jws.com.hanel.de/xsd">0</ns1:returnValue>
</ns2:return>
</ns2:readAllAMDResV04>
</soapenv:Body>
</soapenv:Envelope>
我的 XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:abc="main.jws.com.hanel.de/xsd"
exclude-result-prefixes="abc"
version="1.0" >
<xsl:key name="key" match="article" use="articleNumber"/>
<xsl:template match="/articles">
<result>
<xsl:apply-templates select="article[generate-id() = generate-id(key('key', articleNumber)[1])]"/>
</result>
</xsl:template>
<xsl:template match="article">
<count>
<articleNumber><xsl:value-of select="articleNumber"/></articleNumber>
<totalQuantity><xsl:value-of select="sum(key('key', articleNumber)/inventoryAtStorageLocation)"/></totalQuantity>
</count>
</xsl:template>
</xsl:stylesheet>
到目前为止我的输出:
Aadrapot99900
2
Aadrapot99900
7
Ae13963
128
我正在寻找的输出:
<?xml version="1.0" encoding="utf-8"?>
<DataSet>
<article>
<articleNumber>Aadrapot99900</articleNumber>
<totalQuantity>9</totalQuantity>
</article>
<article>
<articleNumber>Ae13963</articleNumber>
<totalQuantity>128</totalQuantity>
</article>
</DataSet>
我想我必须在某处添加 abc 前缀,但不知道确切的位置,而且我不确定关键结果的匹配。
提前致谢!
这个:
<xsl:template match="/articles">
无法工作,因为在您的输入中没有名为 articles
的元素 - 当然也不是根元素。
尝试将其更改为:
<xsl:template match="ns2:return">
添加 xmlns:ns2="http://main.jws.com.hanel.de"
声明后。您可能还想添加:
<xsl:strip-space elements="*"/>
在样式表的顶部。
这个:
xmlns:abc="main.jws.com.hanel.de/xsd"
错了。实际的命名空间是不同的。必须是:
xmlns:abc="http://main.jws.com.hanel.de/xsd"
修复后,将 所有 对 article
的引用更改为 abc:article
。同样对于它的后代 articleNumber
和 inventoryAtStorageLocation
.
.
我最近问了一个关于 XML 输出错误的问题,原来是因为命名空间被放入了一个元素。
现在我进一步研究了这一点,不幸的是我仍然卡在输出上,因为我不知道现在要给前缀什么。
希望你能帮助我。
下面是我现在拥有的文件和我想要的输出。
我的输入XML:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<ns2:readAllAMDResV04 xmlns:ns2="http://main.jws.com.hanel.de">
<ns2:return>
<article xmlns="http://main.jws.com.hanel.de/xsd">
<articleNumber>Aadrapot99900</articleNumber>
<articleName/>
<inventoryAtStorageLocation>2</inventoryAtStorageLocation>
</article>
<article xmlns="http://main.jws.com.hanel.de/xsd">
<articleNumber>Aadrapot99900</articleNumber>
<articleName/>
<inventoryAtStorageLocation>7</inventoryAtStorageLocation>
</article>
<article xmlns="http://main.jws.com.hanel.de/xsd">
<articleNumber>Ae13963</articleNumber>
<articleName/>
<inventoryAtStorageLocation>128</inventoryAtStorageLocation>
</article>
<article xmlns="http://main.jws.com.hanel.de/xsd">
<articleNumber>PCM11512050E</articleNumber>
<articleName/>
<inventoryAtStorageLocation>68</inventoryAtStorageLocation>
</article>
<ns1:returnValue xmlns:ns1="http://main.jws.com.hanel.de/xsd">0</ns1:returnValue>
</ns2:return>
</ns2:readAllAMDResV04>
</soapenv:Body>
</soapenv:Envelope>
我的 XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:abc="main.jws.com.hanel.de/xsd"
exclude-result-prefixes="abc"
version="1.0" >
<xsl:key name="key" match="article" use="articleNumber"/>
<xsl:template match="/articles">
<result>
<xsl:apply-templates select="article[generate-id() = generate-id(key('key', articleNumber)[1])]"/>
</result>
</xsl:template>
<xsl:template match="article">
<count>
<articleNumber><xsl:value-of select="articleNumber"/></articleNumber>
<totalQuantity><xsl:value-of select="sum(key('key', articleNumber)/inventoryAtStorageLocation)"/></totalQuantity>
</count>
</xsl:template>
</xsl:stylesheet>
到目前为止我的输出:
Aadrapot99900
2
Aadrapot99900
7
Ae13963
128
我正在寻找的输出:
<?xml version="1.0" encoding="utf-8"?>
<DataSet>
<article>
<articleNumber>Aadrapot99900</articleNumber>
<totalQuantity>9</totalQuantity>
</article>
<article>
<articleNumber>Ae13963</articleNumber>
<totalQuantity>128</totalQuantity>
</article>
</DataSet>
我想我必须在某处添加 abc 前缀,但不知道确切的位置,而且我不确定关键结果的匹配。
提前致谢!
这个:
<xsl:template match="/articles">
无法工作,因为在您的输入中没有名为 articles
的元素 - 当然也不是根元素。
尝试将其更改为:
<xsl:template match="ns2:return">
添加 xmlns:ns2="http://main.jws.com.hanel.de"
声明后。您可能还想添加:
<xsl:strip-space elements="*"/>
在样式表的顶部。
这个:
xmlns:abc="main.jws.com.hanel.de/xsd"
错了。实际的命名空间是不同的。必须是:
xmlns:abc="http://main.jws.com.hanel.de/xsd"
修复后,将 所有 对 article
的引用更改为 abc:article
。同样对于它的后代 articleNumber
和 inventoryAtStorageLocation
.
.