[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Unique Nodes

Subject: Re: Unique Nodes
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Sat, 31 Mar 2007 17:00:36 -0300
Re:  Unique Nodes
At 2007-03-31 14:53 -0400, Karthik wrote:
I am new to XSLT.

Welcome!


I have to grab the unique Products from the Input below using XSLT 1.0

INPUT:
...
Desired OUTPUT:
...
The code which I am trying is

<xsl:variable name="unique-Product"
select="//Proposal/Quote/Products/Product[not(ProductId=ancestor::Product/ProductId)]"/>

      <xsl:for-each select="$unique-Product">
      </xsl:for-each>

Your use of axes in this fashion won't work ... you should look up the Muenchian Method using Google and read how the code below works.


I hope this helps.

. . . . . . . . . . Ken

t:\ftemp>type karthik.xml
<Proposal>
      <Quote>
      <QuoteId>1</QuoteId>
              <Products>
                      <Product>
                              <ProdID>
                                      1234
                              </ProdID>
                              <ProdID>
                                      5678
                              </ProdID>
                      </Product>
              </Products>
      </Quote>
      <Quote>
      <QuoteId>2</QuoteId>
              <Products>
                      <Product>
                              <ProdID>
                                      1234
                              </ProdID>
                              <ProdID>
                                      5678
                              </ProdID>
                      </Product>
              </Products>
      </Quote>
</Proposal>

t:\ftemp>type karthik.xsl
<?xml version="1.0" encoding="US-ASCII"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="1.0">

<xsl:output indent="yes"/>
<xsl:key name="prodids" match="ProdID" use="."/>

<xsl:template match="/">
  <Proposal>
    <Products>
      <xsl:for-each select="//ProdID[generate-id(.)=
                                     generate-id(key('prodids',.)[1])]">
        <ProdId><xsl:value-of select="normalize-space(.)"/></ProdId>
      </xsl:for-each>
    </Products>
  </Proposal>
</xsl:template>

</xsl:stylesheet>
t:\ftemp>xslt karthik.xml karthik.xsl con
<?xml version="1.0" encoding="utf-8"?>
<Proposal>
   <Products>
      <ProdId>1234</ProdId>
      <ProdId>5678</ProdId>
   </Products>
</Proposal>
t:\ftemp>


-- World-wide corporate, govt. & user group XML, XSL and UBL training RSS feeds: publicly-available developer resources and training G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (F:-0995) Male Cancer Awareness Aug'05 http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal

Current Thread
  • Unique Nodes
    • Karthik - 28 Mar 2007 22:08:26 -0000
      • Mukul Gandhi - 29 Mar 2007 04:12:25 -0000
      • Karthik - 31 Mar 2007 18:53:27 -0000
        • Message not available
          • G. Ken Holman - 31 Mar 2007 20:01:53 -0000 <=

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.