这里是我需要使用XSLT转换XML源
<?xml version="1.0" encoding="UTF-8"?>
<tns:Grand_Parent_XML xmlns:tns="">
<GrandParent>
<Parent>
<Child>
<Age>3</Age>
</Child>
<Child>
<Gender>Male</Gender>
</Child>
<Child>
<Name>Todd</Name>
</Child>
<Other>1234</Other>
</Parent>
</GrandParent>
</tns:Grand_Parent_XML>
这里是通过XSLT变换后的期望的输出
<?xml version="1.0" encoding="UTF-8"?>
<tns:Grand_Parent_XML xmlns:tns="">
<GrandParent>
<Parent>
<Child>
<Age>3</Age>
<Gender>Male</Gender>
<Name>Todd</Name>
</Child>
<Other>1234</Other>
</Parent>
</GrandParent>
</tns:Grand_Parent_XML>
下面是实际发生...
<?xml version="1.0" encoding="UTF-8"?>
<tns:Grand_Parent_XML xmlns:tns="">
<GrandParent>
<Child>
<Age>3</Age>
<Gender>Male</Gender>
<Name>Todd</Name>
</Child>
</GrandParent>
</tns:Grand_Parent_XML>
而我使用这个XSLT ...
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns="">
<xsl:template match="Grand_Parent_XML/GrandParent/Parent">
<Child>
<xsl:for-each select="Child">
<xsl:if test="Age !=''">
<Age><xsl:value-of select="Age"/></Age>
</xsl:if>
<xsl:if test="Gender !=''">
<Gender><xsl:value-of select="Gender"/></Gender>
</xsl:if>
<xsl:if test="Name !=''">
<Name><xsl:value-of select="Nanme"/></Name>
</xsl:if>
</xsl:for-each>
</Child>
</xsl:template>
</xsl:stylesheet>
我有XSLT的小命令的那一刻,我将不胜感激任何帮助我能。 使用我创建了XSLT,家长被孩子不应该是这样的覆盖。 此外,家长IE之外的其他子节点被删除。 我使用的是实际的XML有一个比我这里包括远远更多的领域。 我可以选择手动包括在XSLT的所有节点,但我觉得有一个更有效的方式来做到这一点。 谢谢!