|
Subject: [xsl] How to avoid duplicated items in result tree From: Ramnivas Laddad <ramnivas@xxxxxxx> Date: Tue, 29 May 2001 16:51:31 -0700 |
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 |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] template match attributes, Bob DuCharme | Thread | [xsl] Entity Reference Questions, Albert Tsun |
| RE: [xsl] How to perse the whole so, Mohammed Rahman | Date | RE: [xsl] Re:Re:How to simplify the, Yang |
| Month |