收录日期:2019/04/18 21:11:37 时间:2010-06-22 23:08:30 标签:xml,xslt

I have a huge XML that i need to work on, but i only need a node of the several in the root. The problem is that, in that node, i got one child that need to be remove. Anyone care to explain if this is possible and, if it is, how can be done? This is a sample of the XML that i got:

    <XML>
 <Properties>
  Contend
 </Properties>
 <Events>
  Contend
 </Events>
 <Contracts>
  Contend
 </Contracts>
 <Trades>
  Contend 
 </Trades>
 <Deals>
  <Deal>
   <Edition>
    <Object>
     <Values>
      <Value>N</Value>
      <Value>N</Value>
     </Values>
    </Object>
    <Members>
     <memberValue>
      <member>template</member>
      <member>template</member>
      <member>
       <Object>
        <Flows>
         <Cupom>
          <Period>
           <Calculation>
            <Data>N</Data>
            <Data>N</Data>
            <Rate>
             <Data>N</Data>
             <Data>N</Data>
             <observations>
              Tons of Contend
             </observations>
            </Rate>
           </Calculation>
          </Period>
         </Cupom>
         <Cupom>
          <Period>
           <Calculation>
            <Data>N</Data>
            <Data>N</Data>
            <Rate>
             <Data>N</Data>
             <Data>N</Data>
             <observations>
              Tons of Contend
             </observations>
            </Rate>
           </Calculation>
          </Period>
         </Cupom>
         <Cupom>
          <Period>
           <Calculation>
            <Data>N</Data>
            <Data>N</Data>
            <Rate>
             <Data>N</Data>
             <Data>N</Data>
             <observations>
              Tons of Contend
             </observations>
            </Rate>
           </Calculation>
          </Period>
         </Cupom>
         <Cupom>
          <Period>
           <Calculation>
            <Data>N</Data>
            <Data>N</Data>
            <Rate>
             <Data>N</Data>
             <Data>N</Data>
             <observations>
              Tons of Contend
             </observations>
            </Rate>
           </Calculation>
          </Period>
         </Cupom>
        </Flows>
       </Object>
      </member>
     </memberValue>
    </Members>
   </Edition>
  </Deal>
 </Deals>
</XML>

I need to preserve de Node, but, inside, i need to remove the one. Please note that the node repeats in each of the node. All of them must be removed.

In the end, my XML shoul'd look like this:

    <XML>
 <Deals>
  <Deal>
   <Edition>
    <Object>
     <Values>
      <Value>N</Value>
      <Value>N</Value>
     </Values>
    </Object>
    <Members>
     <memberValue>
      <member>template</member>
      <member>template</member>
      <member>
       <Object>
        <Flows>
         <Cupom>
          <Period>
           <Calculation>
            <Data>N</Data>
            <Data>N</Data>
            <Rate>
             <Data>N</Data>
             <Data>N</Data>
            </Rate>
           </Calculation>
          </Period>
         </Cupom>
         <Cupom>
          <Period>
           <Calculation>
            <Data>N</Data>
            <Data>N</Data>
            <Rate>
             <Data>N</Data>
             <Data>N</Data>
            </Rate>
           </Calculation>
          </Period>
         </Cupom>
         <Cupom>
          <Period>
           <Calculation>
            <Data>N</Data>
            <Data>N</Data>
            <Rate>
             <Data>N</Data>
             <Data>N</Data>
            </Rate>
           </Calculation>
          </Period>
         </Cupom>
         <Cupom>
          <Period>
           <Calculation>
            <Data>N</Data>
            <Data>N</Data>
            <Rate>
             <Data>N</Data>
             <Data>N</Data>
            </Rate>
           </Calculation>
          </Period>
         </Cupom>
        </Flows>
       </Object>
      </member>
     </memberValue>
    </Members>
   </Edition>
  </Deal>
 </Deals>
</XML>

Many thanks for anyone that can help.

Cheers!

This transformation:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>
 <xsl:strip-space elements="*"/>

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

 <xsl:template match="/*/*[not(self::Deals)] | Cupom/*/*/*/observations"/>
</xsl:stylesheet>

when performed against the provided XML document, produces the wanted result.