about removing nodes having duplicate attribute in xslt Options
dhirajDac
Posted: Thursday, January 17, 2008 10:29:25 AM
Rank: Newbie

Joined: 1/17/2008
Posts: 6
Hi All,
I have a xml like following:-
<students>
<student type=”gen”></student>
<student type=”oh”></student>
<student type=”sc”></student>
<student type=”st”></student>
<student type=”sc”></student>
<student type=”gen”></student>
<student type=”st”></student>
</students>

and i want to create a xslt to converting this xml into following:--

<students>
<student type=”gen”></student>
<student type=”oh”></student>
<student type=”sc”></student>
<student type=”st”></student>
</students>

Please Help me out.
cpalm
Posted: Thursday, January 17, 2008 11:28:56 AM

Rank: Aficionado

Joined: 7/19/2006
Posts: 164
This should work :-)

Code:
<xsl:variable name="students" select="students/student[not(@type=preceding-sibling::student/@type)]" />
<students>
    <xsl:for-each select="$students">
        <student type="{./@type}"></student>
    </xsl:for-each>
</students>

How it works? It drops any student element that have same type attribute value that preceding sibling student element has (if such value exists in other words).

CPalm, www.cpalm.dk
cpalm
Posted: Thursday, January 17, 2008 11:30:16 AM

Rank: Aficionado

Joined: 7/19/2006
Posts: 164
This should work :-)
Code:

<xsl:variable name="students" select="students/student[not(@type=preceding-sibling::student/@type)]" />
<students>
    <xsl:for-each select="$students">
        <student type="{./@type}"></student>
    </xsl:for-each>
</students>


How it works? It drops any student element that have same type attribute value that preceding sibling student element has (if such value exists in other words).

CPalm, www.cpalm.dk
dhirajDac
Posted: Thursday, January 17, 2008 2:06:23 PM
Rank: Newbie

Joined: 1/17/2008
Posts: 6
Thanx a lot..
It works in this scenario but again i have faced a problem as:-
<studentinfo>
<students>
<student type=”gen”></student>
<student type=”oh”></student>
</students>
<student>
<student type=”sc”></student>
<student type=”st”></student>
</student>
<student>
<student type=”sc”></student>
<student type=”gen”></student>
<student type=”st”></student>
</students>
<students>
</students>
and above given code is not working for this...
and i want to create a xslt to converting this xml into following:--

<students>
<student type=”gen”></student>
<student type=”oh”></student>
<student type=”sc”></student>
<student type=”st”></student>
</students>


Please help me out
cpalm
Posted: Thursday, January 17, 2008 2:52:15 PM

Rank: Aficionado

Joined: 7/19/2006
Posts: 164
here you go

Code:

<xsl:variable name="students" select="//student[not(@type=preceding-sibling::student/@type)]" /> 
<students> 
    <xsl:for-each select="$students"> 
        <student type="{./@type}"></student> 
    </xsl:for-each> 
</students>


CPalm, www.cpalm.dk
Users browsing this topic
Guest


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.