Я пытаюсь преобразовать xml с помощью xslt, но, к сожалению, в результате всегда получаю пустой 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>
Я надеюсь, что вы, ребята, можете мне помочь
В шаблоне узла документа используйте apply-templates
, как этот <xsl:template match = "/"><xsl:apply-templates/></xsl:template>
В шаблоне узла документа используйте apply-templates
, например <xsl:template match = "/"><xsl:apply-templates/></xsl:template>
:
XSLT:
<?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 n0"
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 = "/">
<xsl:apply-templates/>
</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>
ВВОД XML
<?xml version = "1.0" encoding = "UTF-8"?>
<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>
ВЫВОД XML:
<Object xmlns:soap-env = "http://schemas.xmlsoap.org/soap/envelope/"
Type = "Article"
Action = "InsertOrSkip">
<Property Name = "Context" Value = "1"/>
<Property Name = "Description" Value = "Nadelhülse HK 5520"/>
</Object>
<Object xmlns:soap-env = "http://schemas.xmlsoap.org/soap/envelope/"
Type = "Article"
Action = "InsertOrSkip">
<Property Name = "Context" Value = "1"/>
<Property Name = "Description" Value = "Buchse / --806"/>
</Object>
ЗАМЕТКА: Вы можете использовать корневой элемент в шаблоне документа, иначе он не будет сформирован.
БЫВШИЙ:
<xsl:template match = "/">
<root>
<xsl:apply-templates/>
</root>
</xsl:template>
Вы действительно получаете пустой документ или получаете только слово «Тест»? (См. xsltfiddle.liberty-development.net/6qVRKx3 для воссоздания проблемы). Спасибо