XPath to exclude certain XML elements?

后端 未结 1 679
别跟我提以往
别跟我提以往 2020-12-18 16:57

I have now read many (maybe all) posts on excluding elements in XPath and I just do not get this working. I have no clue why.

Let\'s say I have the following structu

相关标签:
1条回答
  • 2020-12-18 17:28

    XPath is for selection. What you want to select does not exist in your XML document.

    You need another tool such as XSLT to generate an XML output document based on an input XML document. XSLT can generate your desired output trivially via the identity transformation supplemented with a simple template that suppresses the copying of the element that you do not want (elemC):

    <?xml version="1.0" encoding="UTF-8"?>
    <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="elemC"/>
    </xsl:stylesheet>
    

    XPath alone cannot help you.

    0 讨论(0)
提交回复
热议问题