我正在关注xml:
<?xml version="1.0" encoding="UTF-8"?>
<Types>
<Type ID="1A" type="Generic" BasicID="1a1">
<properties>
<property name="ID" value="1A" />
<property name="Name" value="ABC" />
<property name="Dept" value="DEF" />
</properties>
<relationships>
<relationship name = "Dependant1" value ="Father"/>
<relationship name = "Dependant2" value ="Mother"/>
<relationship name = "Dependant3" value ="Spouse"/>
</relationships>
</Type>
</Types>
我想将其转换为:
<?xml version="1.0" encoding="UTF-8"?>
<Types>
<ID>1A</ID>
<Name>ABC</Name>
<Dept>DEF</Dept>
<Dependant1>Father</Dependant1>
<Dependant1>Mother</Dependant1>
<Dependant1>Spouse</Dependant1>
</Types>
我是XSLT的新手,请帮我解决这个问题。 谢谢,
答案 0 :(得分:1)
元素的转换是用
完成的<xsl:template match="property | relationship">
<xsl:element name="{@name}">
<xsl:value-of select="@value"/>
</xsl:element>
</xsl:template>
然后添加
<xsl:template match="/*">
<xsl:copy>
<xsl:apply-templates select="//property | //relationship"/>
</xsl:copy>
</xsl:template>
你有样式表。