|
|
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.
|
|
 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
|
|
 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
|
|
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
|
|
 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
|
|
|
Guest |