【发布时间】:2018-10-29 11:11:02
【问题描述】:
我正在尝试使用 xslt 转换 xml,但不幸的是,我总是得到一个空的 xml。我猜比赛有问题
XML: https://pastebin.com/fV9Au20L
<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
<soap-env:Header/>
<soap-env:Body>
<n0:ZPmUltimoArtikelResponse xmlns:n0="urn:sap-com:document:sap:soap:functions:mc-style">
<TArtikel>
<item>
<Niederlassung>TKD</Niederlassung>
<Matnr>34459</Matnr>
<Maktx>Nadelhülse HK 5520</Maktx>
<Meins>ST</Meins>
<Preis>7.0</Preis>
<Chargenpflicht/>
</item>
<item>
<Niederlassung>TKD</Niederlassung>
<Matnr>06182</Matnr>
<Maktx>Buchse / --806</Maktx>
<Meins>ST</Meins>
<Preis>24.7</Preis>
<Chargenpflicht/>
</item>
</TArtikel>
</n0:ZPmUltimoArtikelResponse>
</soap-env:Body>
</soap-env:Envelope>
xslt: https://pastebin.com/TGLYwWeL
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xml="http://www.w3.org/XML/1998/namespace" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/" exclude-result-prefixes=" xml xsl" xmlns:n0="urn:sap-com:document:sap:soap:functions:mc-style">
<xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">Test</xsl:template>
<xsl:template match="/soap-env:Envelope/soap-env:Body/n0:ZPmUltimoArtikelResponse/TArtikel">
test2
<xsl:for-each select="item">
test3
<Object Type="Article" Action="InsertOrSkip">
<Property Name="Context" Value="1"/>
<Property Name="Description">
<xsl:attribute name="Value"><xsl:value-of select="Maktx"/></xsl:attribute>
</Property>
</Object>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
希望大家帮帮我
【问题讨论】:
-
您实际上得到的是一个空文档,还是只得到“测试”字样的输出? (请参阅xsltfiddle.liberty-development.net/6qVRKx3 以重新解决该问题)。谢谢
-
在文档节点模板中使用
apply-templates这样<xsl:template match="/"><xsl:apply-templates/></xsl:template>