我有跟随xml,我想得到"员工"具有所有子员工节点的节点,其部门为" HR"。我怎么能在XSLT中做到这一点:
<Company>
<Employees>
<Employee>
<Id>1</Id>
<Department>HR</Department>
</Employee>
<Employee>
<Id>2</Id>
<Department>IT</Department>
</Employee>
<Employee>
<Id>3</Id>
<Department>HR</Department>
</Employee>
</Employees>
</Company>
答案 0 :(得分:0)
这会将您的文档转换为类似的文档,但没有那些讨厌的IT员工。
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/ | @* | node()">
<xsl:copy><xsl:apply-templates select="@* | node()" /></xsl:copy>
</xsl:template>
<xsl:template match="Employee">
<xsl:if test="Department='HR'">
<xsl:copy><xsl:apply-templates select="@* | node()" /></xsl:copy>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
结果:
<?xml version="1.0"?>
<Company>
<Employees>
<Employee>
<Id>1</Id>
<Department>HR</Department>
</Employee>
<Employee>
<Id>3</Id>
<Department>HR</Department>
</Employee>
</Employees>
</Company>