Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#XSLT删除节点_C#_Xslt - Fatal编程技术网

C#XSLT删除节点

C#XSLT删除节点,c#,xslt,C#,Xslt,有人能帮我吗。我需要在C#中删除节点“xsl:variable”,正如您所看到的,这里有两个xsl:template节点,其子元素为xsl:variable。在这个示例中,我需要用C#删除它 大概是这样的: XmlDocument d = new XmlDocument(); d.Load("MyFileName.Xml"); XmlNode t = d.SelectSingleNode("/navigation/page[@id='1']"); t.ParentNode.RemoveChild

有人能帮我吗。我需要在C#中删除节点“xsl:variable”,正如您所看到的,这里有两个xsl:template节点,其子元素为xsl:variable。在这个示例中,我需要用C#删除它

大概是这样的:

XmlDocument d = new XmlDocument();
d.Load("MyFileName.Xml");
XmlNode t = d.SelectSingleNode("/navigation/page[@id='1']");
t.ParentNode.RemoveChild(t);
d.Save();
但我无法获取指向d的“xsl:variable”的路径

请帮帮我

这是XSLT:

<xsl:template name="Aggregate:RealECBooleanToXMLBoolean">
        <xsl:param name="RealECBoolean" select="/.."/>
        <xsl:variable name="var1_result">
            <xsl:value-of select="($RealECBoolean = 'Yes')"/>
            <xsl:value-of select="($RealECBoolean = 'YES')"/>
            <xsl:value-of select="($RealECBoolean = 'X')"/>
        </xsl:variable>
        <xsl:variable name="var2_resultof_any" select="boolean(translate(normalize-space($var1_result), 'false0 ', ''))"/>
        <xsl:choose>
            <xsl:when test="string((string((string($var2_resultof_any) != 'false')) != 'false')) != 'false'">
                <xsl:value-of select="(string((string($var2_resultof_any) != 'false')) != 'false')"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="false()"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    <xsl:template name="Aggregate:LookupRECodeName">
        <xsl:param name="RECode" select="/.."/>
        <xsl:call-template name="vmf:vmf1_inputtoresult">
            <xsl:with-param name="input" select="$RECode"/>
        </xsl:call-template>
    </xsl:template>


这里有一个想法。我不确定在使用SelectNodes时是否需要“xsl”名称空间,您必须对此进行试验

公共方法() {


}

您需要将定义
xsl
前缀的名称空间管理器传递到
SelectNodes
SelectSingleNode

XmlNamespaceManager namespaceManager = new XmlNamespaceManager(xDoc.NameTable);
namespaceManager.AddNamespace("xsl" , "http://www.w3.org/1999/XSL/Transform");
然后:

XmlNode variableNode = xDoc.SelectSingleNode("//xsl:variable", namespaceManager);
将选择第一个
xsl:variable
元素,或

XmlNodeList variableNodes = xDoc.SelectNodes("//xsl:variable", namespaceManager);

将选择所有
xsl:variable
元素

它可能找不到节点,因为没有定义“xsl:”命名空间。此链接可能会有所帮助:谢谢M3NTA7,我有一个获取所有xsl:template节点的代码,但下一步是删除所有子xsl:variable节点,我无法使用此示例。需要单节点值。再次感谢M3NTA7,我发现我在root.SelectNodes(“//xsl:template”))部分有问题。我试图删除xsl,但再次出现错误。我发现我需要XmlNamespaceManager namespaceManager=newxmlnamespacemanager(xDoc.NameTable);'namespaceManager'然后出现此错误'未定义名称空间前缀'xsl'。您仍然有问题吗?这将有助于我们看到代码。这样我们可以看到您正在尝试什么。是的,我仍然有问题,可能是我可以向您发送xsl文件吗?
XmlNodeList variableNodes = xDoc.SelectNodes("//xsl:variable", namespaceManager);