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

How to avoid duplicated items in result tree

Subject: How to avoid duplicated items in result tree
From: Ramnivas Laddad <ramnivas@xxxxxxx>
Date: Tue, 29 May 2001 16:51:31 -0700
the template name is duplicated.
Hello,

I am facing this problem of avoiding duplicate entries in the result tree.
Can somebody please help?

Given XML file such as follows:
<?xml version="1.0"?>
<structure>
    <element name="A_AB">
        <superclass type="A"/>
        <superclass type="A_B"/>
    </element>
    <element name="A_B">
        <superclass type="A"/>
        <superclass type="B"/>
    </element>
    <element name="A"/>
    <element name="B"/>
    <element name="X"/>
</structure>

I want to extract all direct and indirect superclasses of a given element (supplied
as a parameter)

I am trying the following stylesheet:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>

<xsl:template match="/">
    <elementDetails name = "{$elementToExtract}">
	<xsl:call-template name="printElement">
	    <xsl:with-param name="elementName" select="$elementToExtract"/>
        </xsl:call-template>
    </elementDetails>
</xsl:template>

<xsl:template name="printElement">
    <xsl:param name="elementName"/>

    <xsl:copy-of select="//element[@name=$elementName]"/>

    <xsl:for-each select="//element[@name=$elementName]/superclass">
    	<xsl:call-template name="printElement">
	    <xsl:with-param name="elementName" select="@type"/>	
	</xsl:call-template>
    </xsl:for-each>
</xsl:template>

</xsl:stylesheet>

This stylesheet produced follwing output for element A_AB:
(Command: java org.apache.xalan.xslt.Process -in structure.xml -xsl extract.xsl 
	-param elementToExtract A_AB )

<?xml version="1.0" encoding="UTF-8"?>
<elementDetails name="A_AB">
	<element name="A_AB">
		<superclass type="A"/>
		<superclass type="A_B"/>
	</element>
	<element name="A"/>
	<element name="A_B">
		<superclass type="A"/>
		<superclass type="B"/>
	</element>
	<element name="A"/>  <!-- <<< I will like to avoid this duplicated entry -->
	<element name="B"/>
</elementDetails>

Can somebody suggest me a way to avoid duplicate entries (in above case,
one of the element A) in the result tree.

Thanks.

-Ramnivas

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

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.