Ich möchte gerne eine XML mittels XSLT transformieren. Dabei wird bei einem Element immer ein leere xmlns-Attribute übergeben. Meine bisherige Google-Recherche liefert in meinen Augen für mein Problem nicht die passende Lösung. Vielleicht liegt es auch an meinem Verständnis und ich suche nun Hilfe hier.
Hier das Quell-XML was ich transformieren möchte.
Hier das für die Transformation verwendete XSL.
Hier der Output des Ziel-XML mit dem leeren xmlns-Attribut. Dieses Attribut bekomme ich nicht raus. Es muss aber da weg, da das System wo ich dieses XML importieren möchte, damit nicht zurecht kommt.
Hier das Quell-XML was ich transformieren möchte.
Code:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> <Root> <Row> <KENUM>MONITOR1</KENUM> <ALN_KCIINVENTARNR>12345</ALN_KCIINVENTARNR> <STATUS>BETRIEB</STATUS> <LOCATION>LOC</LOCATION> <ALN_KCINUTZUNGSART>Mobil</ALN_KCINUTZUNGSART> </Row> </Root>
Code:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" indent="yes" omit-xml-declaration="yes" /> <xsl:strip-space elements="*"/> <xsl:template match="@*|node()"> <xsl:if test=". != '' or ./@* != ''"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:if> </xsl:template> <xsl:template match="Root"> <SyncSet xmlns="http://myns.de" baseLanguage="DE" transLanguage="DE" event="0"> <MXOSSet> <xsl:apply-templates select="@*|node()"/> </MXOSSet> </SyncSet> </xsl:template> <xsl:template match="Row"> <KE> <xsl:apply-templates select="node()"/> </KE> </xsl:template> <xsl:template match="*[(contains(name(),'ALN_')) and current()!='']"> <SPEC> <ASSETATTRID> <xsl:value-of select="substring-after(name(),'ALN_')" /> </ASSETATTRID> <ALNVALUE> <xsl:value-of select="." /> </ALNVALUE> <SECTION /> <TABLEVALUE /> </SPEC> </xsl:template> </xsl:stylesheet>
Code:
<SyncSet xmlns="http://myns.de" baseLanguage="DE" transLanguage="DE" event="0"> <MXOSSet> <KE xmlns=""> <KENUM>MONITOR1</KENUM> <SPEC> <ASSETATTRID>KCIINVENTARNR</ASSETATTRID> <ALNVALUE>12345</ALNVALUE> <SECTION/> <TABLEVALUE/> </SPEC> <STATUS>BETRIEB</STATUS> <LOCATION>LOC</LOCATION> <SPEC> <ASSETATTRID>KCINUTZUNGSART</ASSETATTRID> <ALNVALUE>Mobil</ALNVALUE> <SECTION/> <TABLEVALUE/> </SPEC> </KE> </MXOSSet> </SyncSet>
Comment