XPath filter filter

I have xml containing the following information, I use Xpath to parse it

<root>
  <a>
    <b></b>
    <c></c>
    <d></d>
  </a>
  <a>
    <b></b>
    <c></c>
    <d></d>
  </a>
</root>

my goal is to get the nodelist from the tag 'a' and in each subblock containing 'b' and 'c' (etc. filter out 'd'!) what I am doing now is use '/ root / a' to get the nodes containing all 'a', 'b' and 'c' and then get rid of 'c', what I set up for this does filtering in XPath instead of using extra code, is there anyway can do it thank!

+3
source share
1 answer

You can filter the element by copying everything using the template below and just intercept the elements you want to filter.

<xsl:stylesheet version="1.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">


  <xsl:template match="a/d"/>


  <xsl:template match="node() | @*">
    <xsl:copy>
      <xsl:apply-templates select="node() | @*"/>
    </xsl:copy>
  </xsl:template>

</xsl:stylesheet> 

, . , , d a. , .. .

+2

All Articles