将XML文件更改属性值转换为属性,将值转换为属性值



有没有一种方法可以让"切换"?在XML中,正如我在标题中解释的那样,将属性值更改为标记的属性,并将值更改为标记的属性值。例子:

<attribute name="Krantyp">value</attribute>
<attribute name="Beschreibung">value2</attribute>

变成这样:

<attribute Krantyp="value" Beschreibung="value2"/>

所以,在这个例子中,标签是"attribute",属性名的值必须变成attribute (name不存在了!),这里" krantype "成为新属性。的价值标签"value"成为新属性的值" krantype "等等。

这可能吗?如果是,最好的方法是什么?

看一下

输入XML

<root>
<attribute name="Krantyp">value</attribute>
<attribute name="Beschreibung">value2</attribute>
</root>
XSLT>
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="utf-8" indent="yes" omit-xml-declaration="yes"/>
<xsl:template match="root">
<xsl:copy>
<attribute>
<xsl:for-each select="attribute">
<xsl:attribute name="{@name}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:for-each>
</attribute>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

输出XML

<root>
<attribute Krantyp="value" Beschreibung="value2"/>
</root>

最新更新