-1

for example below is the xml

<products>
    <product>
        <name>Pen</name>
        <Quantity>2</Quantity>
        <Amount><Price>2</Price><Currency>USD</Currency></Amount>
    </product> 
    <product>
        <name>Pencil</name>
        <Quantity>20</Quantity>
        <Amount><Price>2</Price><Currency>USD</Currency></Amount>
    </product>
    <product>
        <name>Bag</name>
        <Quantity>25</Quantity>
        <Amount><Price>2</Price><Currency>USD</Currency></Amount>
    </product>
</products>

in my xsl i using like below to remove

<xsl:copy-of select="node()[not(self::Quantity)]"/>

I also need to remove sub node <Currency> from the <Amount>

i try like below

<xsl:copy-of select="node()[not(self::Quantity) and not(self::Amount/Currency)]"/>

but not working fine . it will remove all node's from <Amount>

How i remove sub node <Currency> only?

user475464
  • 1,741
  • 10
  • 26
  • 38
  • 1
    You haven't provided a complete XSLT transformation, nor have you provided the exact wanted result. Mentioning in the comments that you "can't use `` method " disqualifies this question from belonging to the "xslt" tag... – Dimitre Novatchev Feb 21 '12 at 14:50
  • I agree with hon' @DimitreNovatchev .. – Rookie Programmer Aravind Feb 22 '12 at 04:45
  • @infantprogrammer'Aravind': :) I just +1-ed your answer and one of your comments. Should I also call you "hon'", or will it have a different meaning? :) – Dimitre Novatchev Feb 22 '12 at 05:16
  • @DimitreNovatchev, thank you :) well. hon word doesn't suit rookies :) yes it does make a difference .. of a class :D – Rookie Programmer Aravind Feb 22 '12 at 07:36
  • @DimitreNovatchev, Usage of C# script in XSLT file, I had learnt from you :) I use it heavily .. Indeed have suggested to many beginners .. and just now someone accepted it .. http://stackoverflow.com/questions/9394322/xslt-1-0-get-current-datetime/9394846#comment11871922_9394846 – Rookie Programmer Aravind Feb 22 '12 at 14:11

1 Answers1

2

If you really want to use self

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

or if you want to know other simpler way :)

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

The above templates copy all other tags except <Currency>

EDIT: Replace the below code

<xsl:template match="product">
   <product>
    <xsl:for-each select="key('kProdByName', name)">
      <xsl:if test="position() = 1">
        <xsl:copy-of select="node()"/>
      </xsl:if>
    </xsl:for-each>
   </product>
</xsl:template>

By this: (hope it works)

  <xsl:template match="product">
    <product>
      <xsl:for-each select="key('kProdByName', name)">
        <xsl:if test="position() = 1">
          <xsl:apply-templates select="node()|@*"/>
      </xsl:if>
      </xsl:for-each>
    </product>
  </xsl:template>

  <xsl:template match="Currency|Quantity"/>
Rookie Programmer Aravind
  • 11,952
  • 23
  • 81
  • 114