【问题标题】:Generate XML tags form XML attributes [closed]从 XML 属性生成 XML 标记 [关闭]
【发布时间】:2014-11-06 18:03:50
【问题描述】:

我有以下 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 很陌生,请帮我解决这个问题。 谢谢,

【问题讨论】:

    标签: xml xslt xml-parsing


    【解决方案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>
    

    你有样式表。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-05-23
      • 1970-01-01
      • 2014-06-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-23
      相关资源
      最近更新 更多