Looking to convert tablular xml data into heatmap like matrix via xslt and the Muenchian Method -
i have been reading on muenchian method, not understanding grouping generate html formatted how need it.
here source xml.
<?xml version="1.0" encoding="utf-8"?> <env> <paramcount>4</paramcount> <param parameter="id" value="1371"/> <param parameter="xform" value="none"/> <param parameter="user" value="administrator"/> <param parameter="time-stamp" value="jun 5, 2012 2:29:45 pm"/> <sql name="matrix demo" qid="1371"> <row num="1"> <col meta="matrix.x_title" grp="0" label="x" type="12" name="x">1-sample topic</col> <col meta="matrix.x_id" grp="0" label="x_id" type="2" name="x_id">3838</col> <col meta="matrix.y_title" grp="0" label="y" type="12" name="y">dc</col> <col meta="matrix.y_id" grp="0" label="y_id" type="2" name="y_id">4909</col> <col meta="matrix.priority" grp="0" label="priority" type="2" name="priority">1740</col> </row> <row num="2"> <col meta="matrix.x_title" grp="0" label="x" type="12" name="x">1-sample topic</col> <col meta="matrix.x_id" grp="0" label="x_id" type="2" name="x_id">3838</col> <col meta="matrix.y_title" grp="0" label="y" type="12" name="y">maryland</col> <col meta="matrix.y_id" grp="0" label="y_id" type="2" name="y_id">4910</col> <col meta="matrix.priority" grp="0" label="priority" type="2" name="priority">1740</col> </row> <row num="3"> <col meta="matrix.x_title" grp="0" label="x" type="12" name="x">1-sample topic</col> <col meta="matrix.x_id" grp="0" label="x_id" type="2" name="x_id">3838</col> <col meta="matrix.y_title" grp="0" label="y" type="12" name="y">virginia</col> <col meta="matrix.y_id" grp="0" label="y_id" type="2" name="y_id">4908</col> <col meta="matrix.priority" grp="0" label="priority" type="2" name="priority">1740</col> </row> <row num="4"> <col meta="matrix.x_title" grp="0" label="x" type="12" name="x">2-sample topic</col> <col meta="matrix.x_id" grp="0" label="x_id" type="2" name="x_id">4901</col> <col meta="matrix.y_title" grp="0" label="y" type="12" name="y">dc</col> <col meta="matrix.y_id" grp="0" label="y_id" type="2" name="y_id">4909</col> <col meta="matrix.priority" grp="0" label="priority" type="2" name="priority">1741</col> </row> <row num="5"> <col meta="matrix.x_title" grp="0" label="x" type="12" name="x">2-sample topic</col> <col meta="matrix.x_id" grp="0" label="x_id" type="2" name="x_id">4901</col> <col meta="matrix.y_title" grp="0" label="y" type="12" name="y">maryland</col> <col meta="matrix.y_id" grp="0" label="y_id" type="2" name="y_id">4910</col> <col meta="matrix.priority" grp="0" label="priority" type="2" name="priority">1741</col> </row> <row num="6"> <col meta="matrix.x_title" grp="0" label="x" type="12" name="x">2-sample topic</col> <col meta="matrix.x_id" grp="0" label="x_id" type="2" name="x_id">4901</col> <col meta="matrix.y_title" grp="0" label="y" type="12" name="y">virginia</col> <col meta="matrix.y_id" grp="0" label="y_id" type="2" name="y_id">4908</col> <col meta="matrix.priority" grp="0" label="priority" type="2" name="priority">1741</col> </row> ... </sql> </env> this trying achieve.
<html> <body> <table border="1" width="500px"> <thead> <tr> <th> </th> <th>1-sample topic</th> <th>2-sample topic</th> <th>3-sample topic</th> </tr> </thead> <tbody> <tr> <td>dc</td> <td>1740</td> <td>1741</td> <td>1742</td> </tr> <tr> <td>maryland</td> <td>1740</td> <td>1741</td> <td>1742</td> </tr> <tr> <td>virginia</td> <td>1740</td> <td>1741</td> <td>1742</td> </tr> </tbody> </table> </body> </html> i haven't come close getting output need it. did example http://www.jenitennison.com/xslt/grouping/muenchian.html did not further that.
i can control data comes out in col sections, overall tree cannot change. appreciated.
you don't of <col> elements reliable ones group on, presume ones name="x_id" , name="y_id" appropriate.
the purpose of muenchian method locate elements identical characteristic. in case need group rows value of x_id columns find text go in <th> elements of first row, , separately value of y_id columns determine rows display in <td> elements of subsequent lines.
this stylesheet grouping specified. output when applied data have given shown beneath it.
<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/xsl/transform" version="1.0"> <xsl:output method="html" indent="yes"/> <xsl:strip-space elements="*"/> <xsl:key name="rows_by_x_id" match="row" use="col[@name='x_id']" /> <xsl:key name="rows_by_y_id" match="row" use="col[@name='y_id']" /> <xsl:template match="/env/sql"> <html> <body> <table border="1" width="500px"> <tr> <th> </th> <xsl:for-each select="row[generate-id() = generate-id(key('rows_by_x_id', col[@name='x_id']))]"> <th> <xsl:value-of select="col[@name='x']"/> </th> </xsl:for-each> </tr> <xsl:for-each select="row[generate-id() = generate-id(key('rows_by_y_id', col[@name='y_id']))]"> <tr> <td> <xsl:value-of select="col[@name='y']"/> </td> <xsl:for-each select="key('rows_by_y_id', current()/col[@name='y_id'])"> <td> <xsl:value-of select="col[@name='priority']"/> </td> </xsl:for-each> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet> output
4<html> <body> <table border="1" width="500px"> <tr> <th> </th> <th>1-sample topic</th> <th>2-sample topic</th> </tr> <tr> <td>dc</td> <td>1740</td> <td>1741</td> </tr> <tr> <td>maryland</td> <td>1740</td> <td>1741</td> </tr> <tr> <td>virginia</td> <td>1740</td> <td>1741</td> </tr> </table> </body> </html>
Comments
Post a Comment