如何删除外部XML文件中引用的特定节点和子节点?
我有一个很大的XML文件,我需要删除整个学生节点以及其中一个实例节点的ownist与另一个XML文件中的一个匹配的学生节点中的所有子节点 我的大型XML文件“file1.XML”的格式如下:如何删除外部XML文件中引用的特定节点和子节点?,xml,xslt,Xml,Xslt,我有一个很大的XML文件,我需要删除整个学生节点以及其中一个实例节点的ownist与另一个XML文件中的一个匹配的学生节点中的所有子节点 我的大型XML文件“file1.XML”的格式如下: <institution> <ukprn>1234</ukprn> <course> <courseID>1</courseID> <courseaim>X99</courseaim> </
<institution>
<ukprn>1234</ukprn>
<course>
<courseID>1</courseID>
<courseaim>X99</courseaim>
</course>
<student>
<birthdate>30/10/1985</birthdate>
<instance>
<OWNINST>123456|5</OWNINST>
<FC>1</FC>
<elq>4</elq>
</instance>
</student>
<student>
<birthdate>01/02/1999</birthdate>
<ybj>76</jbj>
<instance>
<OWNINST>654321|1</OWNINST>
<FC>2</FC>
<elq>2</elq>
</instance>
<instance>
<OWNINST>654321|2</OWNINST>
<FC>6</FC>
<elq>1</elq>
</instance>
</student>
存在多个学生,每个学生可以有多个实例,并且并非所有学生都有所有节点
我有另一个xml文件“File2.xml”,其结构如下:
<studentstodelete>
<OWNINST>555466|2</OWNINST>
<OWNINST>654321|1</OWNINST>
</studentstodelete>
对于File2.xml中的每个学生,我想删除他们的整个学生节点,包括File1.xml中的子节点,如果他们自己的inst列在File2.xml中。不应更改File2.xml中未列出的任何学生
请有人帮我,因为我不知道如何告诉它删除记录
这是我为样式表设计的,但缺少“删除”位:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="no"/>
<xsl:strip-space elements="*"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Student/Instance[OWNINST = document('File2.xml')/studentstodelete/OWNINST]">
</xsl:template>
非常感谢您的帮助
谢谢如果要删除Student元素,则需要更改
<xsl:template match="Student/Instance[OWNINST = document('File2.xml')/studentstodelete/OWNINST]">
</xsl:template>
到
太棒了,谢谢,我知道我就快到了!非常感谢。你昨天也帮了我,谢谢。我想给你投票,但它不让我得票。
<xsl:template match="Student[Instance/OWNINST = document('File2.xml')/studentstodelete/OWNINST]"></xsl:template>