Removing some nodes from an XML document during iteration using XSLT

I have a little problem with some XSLT.

My original XML is as follows:

<?xml version="1.0"?><rowset>
  <row>
    <trans_type>10</trans_type>
    <creation_date>2011-06-07</creation_date>
    <system_id>1039</system_id>
    <transaction_set>
      <transaction>
        <trans_type>10</trans_type>
        <client_id>977400</client_id>
        <case_id>12881459</case_id>
        <invoice_no>01/2011</invoice_no>
        <payment_date>110606</payment_date>
        <payment>710,08</payment>
        <currency>EUR</currency>
        <comment>
          <record_type>612</record_type>
          <comment_text>Asiakas maksoi lisäksi kesäkuun vuokran ajalle 1.6. - 15.6.2</comment_text>
        </comment>
        <comment>
          <record_type>612</record_type>
          <comment_text>011. Meillä saldo 0 €.</comment_text>
        </comment>
      </transaction>
    </transaction_set>
    <subtotal>
      <trans_type>10</trans_type>
      <count>25</count>
    </subtotal>
  </row>
</rowset>

My XSLT looks like this:

<?xml version='1.0' ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
    <rowset>
      <xsl:for-each select="rowset/row/transaction_set/transaction">
        <row>
          <xsl:copy-of select="../../trans_type"/>
          <xsl:copy-of select="../../creation_date"/>
          <xsl:copy-of select="../../subtotal"/>
          <xsl:copy-of select="."/>
          <xsl:copy-of select="./client_id"/>
          <comment_text><xsl:for-each select="./comment"><xsl:value-of select="./comment_text"/></xsl:for-each></comment_text>
        </row>
      </xsl:for-each>
    </rowset>
</xsl:template>
</xsl:stylesheet> 

... and my conclusion is as follows:

<?xml version='1.0' ?>
<rowset>
  <row>
    <trans_type>10</trans_type>
    <creation_date>2011-06-07</creation_date>
    <subtotal>
      <trans_type>10</trans_type>
      <count>25</count>
    </subtotal>
    <transaction>
      <trans_type>10</trans_type>
      <client_id>977400</client_id>           <!--need this gone-->
      <case_id>12881459</case_id>
      <invoice_no>01/2011</invoice_no>
      <payment_date>110606</payment_date>
      <payment>710,08</payment>
      <currency>EUR</currency>                <!--need this gone-->
      <comment>                               <!--need this gone-->
        <record_type>612</record_type>
        <comment_text>Asiakas maksoi lisäksi kesäkuun vuokran ajalle 1.6. - 15.6.2</comment_text>
      </comment>
      <comment>                               <!--need this gone-->
        <record_type>612</record_type>
        <comment_text>011. Meillä saldo 0 €.</comment_text>
      </comment>
    </transaction>
    <client_id>977400</client_id>
    <comment_text>Asiakas maksoi lisäksi kesäkuun vuokran ajalle 1.6. - 15.6.2011. Meillä saldo 0 €.</comment_text>
  </row>
</rowset>

I need to remove the following tags from my output \rowset\row\transaction\comment, \rowset\row\transaction\client_idand \rowset\row\transcation\currency. Although I managed to flip the XML almost the way I want it, I can’t delete the nodes I don’t want.

There can be more than one transactionin the source XML transaction_set, and each transactioncan contain several comment. I am trying to combine all the records comment\comment_textthat I managed to make, but I need these tags commentremoved from \rowset\row\transactionin the XML output.

Maybe I’ll solve it wrong, but I can’t lower my head.

+3
1

- (.. , /), op-op , :

<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="*"/>

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

 <!-- add elements that you want to omit here -->
 <xsl:template match="//client_id"/>
 <xsl:template match="//comment"/>
 ...

</xsl:stylesheet>

:

XSL Transform Xml-

+2

All Articles