EDN Admin
Well-known member
Hi,
I am transforming my XML into an HTML using XSLT.
Till now my XSLT is as below :
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; <?<span style="color:#A31515; xml <span style="color:Red; version<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1.0<span style="color:Black; " <span style="color:Red; encoding<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; utf-8<span style="color:Black; "<span style="color:Blue; ?>
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; stylesheet <span style="color:Red; version<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1.0<span style="color:Black; "
<span style="color:Red; xmlns:xsl<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; http://www.w3.org/1999/XSL/Transform<span style="color:Black; "
<span style="color:Red; xmlns:rs<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; urn:schemas-microsoft-com:rowset<span style="color:Black; " <span style="color:Red; xmlns:z<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; #RowsetSchema<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; output <span style="color:Red; method<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; html<span style="color:Black; " <span style="color:Red; indent<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; yes<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; param <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; groups<span style="color:Black; " <span style="color:Red; select<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; //rs:data//z:row[not(@GroupName=preceding-sibling::z:row/@GroupName)]<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; key <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; k1<span style="color:Black; " <span style="color:Red; match<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Users/User<span style="color:Black; " <span style="color:Red; use<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; @Name<span style="color:Black; "<span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; template <span style="color:Red; match<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; /<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; for-each <span style="color:Red; select<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; $groups<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; sort <span style="color:Red; select<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; @GroupName<span style="color:Black; " <span style="color:Red; order<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; descending<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; sort <span style="color:Red; select<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; @User<span style="color:Black; " <span style="color:Red; order<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; ascending<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; variable <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; group<span style="color:Black; " <span style="color:Red; select<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; @GroupName<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; choose<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; when <span style="color:Red; test<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; @GroupName != <span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; div<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; div<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; div<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; h3<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; apply-templates <span style="color:Red; select<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; @GroupName<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; </<span style="color:#A31515; h3<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; div<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; for-each <span style="color:Red; select<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; //rs:data/z:row[@GroupName=$group]<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; variable <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; user<span style="color:Black; " <span style="color:Red; select<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; key(k1, substring-after(@User,#))<span style="color:Black; "<span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; div<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; div<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; table <span style="color:Red; cellpadding<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 0<span style="color:Black; " <span style="color:Red; cellspacing<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 0<span style="color:Black; " <span style="color:Red; border<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 0<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; tbody<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; tr<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; tr<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; td<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; div <span style="color:Red; class<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; items<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; div <span style="color:Red; class<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; item<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; text<span style="color:Blue; > <span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; text<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; value-of <span style="color:Red; select<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; substring-after(@User,#)<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; </<span style="color:#A31515; div<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; div<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; td<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; tr<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; tr<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; tbody<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; table<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; div<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; div<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; for-each<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; div<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; div<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; when<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; choose<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; for-each<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; div<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; div<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; div<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; h3<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; text<span style="color:Blue; >Others<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; text<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; h3<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; div<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; for-each <span style="color:Red; select<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; $groups<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; choose<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; when <span style="color:Red; test<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; @GroupName != <span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; when<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; otherwise<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; variable <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; user<span style="color:Black; " <span style="color:Red; select<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; key(k1, substring-after(@User,#))<span style="color:Black; "<span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; div<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; div<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; table <span style="color:Red; cellpadding<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 0<span style="color:Black; " <span style="color:Red; cellspacing<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 0<span style="color:Black; " <span style="color:Red; border<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 0<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; tbody<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; tr<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; tr<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; td<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; div <span style="color:Red; class<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; items<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; div <span style="color:Red; class<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; item<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; text<span style="color:Blue; > <span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; text<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; value-of <span style="color:Red; select<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; substring-after(@User,#)<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; </<span style="color:#A31515; div<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; div<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; td<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; tr<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; tr<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; tbody<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; table<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; div<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; div<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; otherwise<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; choose<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; for-each<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; div<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; div<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; template<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; stylesheet<span style="color:Blue; >
[/code]
And my XML is as below:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; <<span style="color:#A31515; xml <span style="color:Red; xmlns:s<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882<span style="color:Black; " <span style="color:Red; xmlns:dt<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; uuid:C2F41010-65B3-11d1-A29F-00AA00C14882<span style="color:Black; " <span style="color:Red; xmlns:rs<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; urn:schemas-microsoft-com:rowset<span style="color:Black; " <span style="color:Red; xmlns:z<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; #RowsetSchema<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; rs<span style="color:Blue; :<span style="color:#A31515; data <span style="color:Red; ItemCount<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 5<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; z<span style="color:Blue; :<span style="color:#A31515; row <span style="color:Red; GroupName<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Developer<span style="color:Black; " <span style="color:Red; User<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1;#Naimish Pandya_1<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; z<span style="color:Blue; :<span style="color:#A31515; row <span style="color:Red; GroupName<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Manager<span style="color:Black; " <span style="color:Red; User<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1;#Naimish Pandya_2<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; z<span style="color:Blue; :<span style="color:#A31515; row <span style="color:Red; GroupName<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Architect<span style="color:Black; " <span style="color:Red; User<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1;#Naimish Pandya_3<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; z<span style="color:Blue; :<span style="color:#A31515; row <span style="color:Red; User<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1;#Naimish Pandya_4<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; z<span style="color:Blue; :<span style="color:#A31515; row <span style="color:Red; User<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1;#Naimish Pandya_5<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; </<span style="color:#A31515; rs<span style="color:Blue; :<span style="color:#A31515; data<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; xml<span style="color:Blue; >
[/code]
If I ran my XSLT, it gives me below output:
<pre>Manager
Naimish Pandya_2
Developer
Naimish Pandya_1
Architect
Naimish Pandya_3
Others
Naimish Pandya_4
Naimish Pandya_5
[/code]
<br/>
This is just fine.
But, If I change my XML like below:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; <<span style="color:#A31515; xml <span style="color:Red; xmlns:s<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882<span style="color:Black; " <span style="color:Red; xmlns:dt<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; uuid:C2F41010-65B3-11d1-A29F-00AA00C14882<span style="color:Black; " <span style="color:Red; xmlns:rs<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; urn:schemas-microsoft-com:rowset<span style="color:Black; " <span style="color:Red; xmlns:z<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; #RowsetSchema<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; rs<span style="color:Blue; :<span style="color:#A31515; data <span style="color:Red; ItemCount<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 5<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; z<span style="color:Blue; :<span style="color:#A31515; row <span style="color:Red; GroupName<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Developer<span style="color:Black; " <span style="color:Red; User<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1;#Naimish Pandya_1<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; z<span style="color:Blue; :<span style="color:#A31515; row <span style="color:Red; GroupName<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Manager<span style="color:Black; " <span style="color:Red; User<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1;#Naimish Pandya_2<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; z<span style="color:Blue; :<span style="color:#A31515; row <span style="color:Red; GroupName<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Architect<span style="color:Black; " <span style="color:Red; User<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1;#Naimish Pandya_3<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; z<span style="color:Blue; :<span style="color:#A31515; row <span style="color:Red; GroupName<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Architect<span style="color:Black; " <span style="color:Red; User<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1;#Naimish Pandya_4<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; z<span style="color:Blue; :<span style="color:#A31515; row <span style="color:Red; GroupName<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Architect<span style="color:Black; " <span style="color:Red; User<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1;#Naimish Pandya_5<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; </<span style="color:#A31515; rs<span style="color:Blue; :<span style="color:#A31515; data<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; xml<span style="color:Blue; >
[/code]
<br/>
I have added GroupName for last two nodes , my output gets change like below :
<pre>Manager
Naimish Pandya_2
Developer
Naimish Pandya_1
Architect
Naimish Pandya_3
Naimish Pandya_4
Naimish Pandya_5
Others[/code]
<hr class="sig https://twitter.com/#!/NaimishPandya @NaimishPandya | mailtoandya.naimish@hotmail.com
Email | http://www.linkedin.com/in/naimishpandya LinkedIn | http://naimishpandya.wordpress.com/
My Blog
View the full article
I am transforming my XML into an HTML using XSLT.
Till now my XSLT is as below :
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; <?<span style="color:#A31515; xml <span style="color:Red; version<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1.0<span style="color:Black; " <span style="color:Red; encoding<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; utf-8<span style="color:Black; "<span style="color:Blue; ?>
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; stylesheet <span style="color:Red; version<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1.0<span style="color:Black; "
<span style="color:Red; xmlns:xsl<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; http://www.w3.org/1999/XSL/Transform<span style="color:Black; "
<span style="color:Red; xmlns:rs<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; urn:schemas-microsoft-com:rowset<span style="color:Black; " <span style="color:Red; xmlns:z<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; #RowsetSchema<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; output <span style="color:Red; method<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; html<span style="color:Black; " <span style="color:Red; indent<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; yes<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; param <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; groups<span style="color:Black; " <span style="color:Red; select<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; //rs:data//z:row[not(@GroupName=preceding-sibling::z:row/@GroupName)]<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; key <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; k1<span style="color:Black; " <span style="color:Red; match<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Users/User<span style="color:Black; " <span style="color:Red; use<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; @Name<span style="color:Black; "<span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; template <span style="color:Red; match<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; /<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; for-each <span style="color:Red; select<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; $groups<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; sort <span style="color:Red; select<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; @GroupName<span style="color:Black; " <span style="color:Red; order<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; descending<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; sort <span style="color:Red; select<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; @User<span style="color:Black; " <span style="color:Red; order<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; ascending<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; variable <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; group<span style="color:Black; " <span style="color:Red; select<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; @GroupName<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; choose<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; when <span style="color:Red; test<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; @GroupName != <span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; div<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; div<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; div<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; h3<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; apply-templates <span style="color:Red; select<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; @GroupName<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; </<span style="color:#A31515; h3<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; div<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; for-each <span style="color:Red; select<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; //rs:data/z:row[@GroupName=$group]<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; variable <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; user<span style="color:Black; " <span style="color:Red; select<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; key(k1, substring-after(@User,#))<span style="color:Black; "<span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; div<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; div<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; table <span style="color:Red; cellpadding<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 0<span style="color:Black; " <span style="color:Red; cellspacing<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 0<span style="color:Black; " <span style="color:Red; border<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 0<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; tbody<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; tr<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; tr<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; td<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; div <span style="color:Red; class<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; items<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; div <span style="color:Red; class<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; item<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; text<span style="color:Blue; > <span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; text<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; value-of <span style="color:Red; select<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; substring-after(@User,#)<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; </<span style="color:#A31515; div<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; div<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; td<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; tr<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; tr<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; tbody<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; table<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; div<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; div<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; for-each<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; div<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; div<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; when<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; choose<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; for-each<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; div<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; div<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; div<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; h3<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; text<span style="color:Blue; >Others<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; text<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; h3<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; div<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; for-each <span style="color:Red; select<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; $groups<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; choose<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; when <span style="color:Red; test<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; @GroupName != <span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; when<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; otherwise<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; variable <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; user<span style="color:Black; " <span style="color:Red; select<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; key(k1, substring-after(@User,#))<span style="color:Black; "<span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; div<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; div<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; table <span style="color:Red; cellpadding<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 0<span style="color:Black; " <span style="color:Red; cellspacing<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 0<span style="color:Black; " <span style="color:Red; border<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 0<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; tbody<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; tr<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; tr<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; td<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; div <span style="color:Red; class<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; items<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; div <span style="color:Red; class<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; item<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; text<span style="color:Blue; > <span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; text<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; value-of <span style="color:Red; select<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; substring-after(@User,#)<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; </<span style="color:#A31515; div<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; div<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; td<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; tr<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; tr<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; tbody<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; table<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; div<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; div<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; otherwise<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; choose<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; for-each<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; div<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; div<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; template<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; stylesheet<span style="color:Blue; >
[/code]
And my XML is as below:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; <<span style="color:#A31515; xml <span style="color:Red; xmlns:s<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882<span style="color:Black; " <span style="color:Red; xmlns:dt<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; uuid:C2F41010-65B3-11d1-A29F-00AA00C14882<span style="color:Black; " <span style="color:Red; xmlns:rs<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; urn:schemas-microsoft-com:rowset<span style="color:Black; " <span style="color:Red; xmlns:z<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; #RowsetSchema<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; rs<span style="color:Blue; :<span style="color:#A31515; data <span style="color:Red; ItemCount<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 5<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; z<span style="color:Blue; :<span style="color:#A31515; row <span style="color:Red; GroupName<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Developer<span style="color:Black; " <span style="color:Red; User<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1;#Naimish Pandya_1<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; z<span style="color:Blue; :<span style="color:#A31515; row <span style="color:Red; GroupName<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Manager<span style="color:Black; " <span style="color:Red; User<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1;#Naimish Pandya_2<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; z<span style="color:Blue; :<span style="color:#A31515; row <span style="color:Red; GroupName<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Architect<span style="color:Black; " <span style="color:Red; User<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1;#Naimish Pandya_3<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; z<span style="color:Blue; :<span style="color:#A31515; row <span style="color:Red; User<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1;#Naimish Pandya_4<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; z<span style="color:Blue; :<span style="color:#A31515; row <span style="color:Red; User<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1;#Naimish Pandya_5<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; </<span style="color:#A31515; rs<span style="color:Blue; :<span style="color:#A31515; data<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; xml<span style="color:Blue; >
[/code]
If I ran my XSLT, it gives me below output:
<pre>Manager
Naimish Pandya_2
Developer
Naimish Pandya_1
Architect
Naimish Pandya_3
Others
Naimish Pandya_4
Naimish Pandya_5
[/code]
<br/>
This is just fine.
But, If I change my XML like below:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; <<span style="color:#A31515; xml <span style="color:Red; xmlns:s<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882<span style="color:Black; " <span style="color:Red; xmlns:dt<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; uuid:C2F41010-65B3-11d1-A29F-00AA00C14882<span style="color:Black; " <span style="color:Red; xmlns:rs<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; urn:schemas-microsoft-com:rowset<span style="color:Black; " <span style="color:Red; xmlns:z<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; #RowsetSchema<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; rs<span style="color:Blue; :<span style="color:#A31515; data <span style="color:Red; ItemCount<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 5<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; z<span style="color:Blue; :<span style="color:#A31515; row <span style="color:Red; GroupName<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Developer<span style="color:Black; " <span style="color:Red; User<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1;#Naimish Pandya_1<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; z<span style="color:Blue; :<span style="color:#A31515; row <span style="color:Red; GroupName<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Manager<span style="color:Black; " <span style="color:Red; User<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1;#Naimish Pandya_2<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; z<span style="color:Blue; :<span style="color:#A31515; row <span style="color:Red; GroupName<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Architect<span style="color:Black; " <span style="color:Red; User<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1;#Naimish Pandya_3<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; z<span style="color:Blue; :<span style="color:#A31515; row <span style="color:Red; GroupName<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Architect<span style="color:Black; " <span style="color:Red; User<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1;#Naimish Pandya_4<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; z<span style="color:Blue; :<span style="color:#A31515; row <span style="color:Red; GroupName<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Architect<span style="color:Black; " <span style="color:Red; User<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1;#Naimish Pandya_5<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; </<span style="color:#A31515; rs<span style="color:Blue; :<span style="color:#A31515; data<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; xml<span style="color:Blue; >
[/code]
<br/>
I have added GroupName for last two nodes , my output gets change like below :
<pre>Manager
Naimish Pandya_2
Developer
Naimish Pandya_1
Architect
Naimish Pandya_3
Naimish Pandya_4
Naimish Pandya_5
Others[/code]
<hr class="sig https://twitter.com/#!/NaimishPandya @NaimishPandya | mailtoandya.naimish@hotmail.com
Email | http://www.linkedin.com/in/naimishpandya LinkedIn | http://naimishpandya.wordpress.com/
My Blog
View the full article