[Home] [By Thread] [By Date] [Recent Entries]
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 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>
|

Cart



