|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Converting a XML document to a HTML table with ',' delimiter
I have a XML that looks like :
<resultSet recordCount="10" columnCount="2"> <record> <column name="DOMAIN">A</column> <column name="SKU">SKU1</column> </record> <record> <column name="DOMAIN">A</column> <column name="SKU">SKU2</column> </record> <record> <column name="DOMAIN">B</column> <column name="SKU">SKU3</column> </record> <record> <column name="DOMAIN">B</column> <column name="SKU">SKU4</column> </record> <record> <column name="DOMAIN">B</column> <column name="SKU">SKU5</column> </record> <record> <column name="DOMAIN">C</column> <column name="SKU">SKU6</column> </record> <record> <column name="DOMAIN">C</column> <column name="SKU">SKU7</column> </record> <record> <column name="DOMAIN">C</column> <column name="SKU">SKU8</column> </record> <record> <column name="DOMAIN">D</column> <column name="SKU">SKU9</column> </record> <record> <column name="DOMAIN">D</column> <column name="SKU">SKU10</column> </record> </resultSet> I would like to transform this XML document into a HTML table that looks like <html> <body> <table border="1"> <tr> <td>A</td> <td>SKU1, SKU2</td> </tr> <tr> <td>B</td> <td>SKU3,SKU4,SKU5</td> </tr> <tr> <td>C</td> <td>SKU6,SKU7,SKU8</td> </tr> <tr> <td>D</td> <td>SKU9,SKU10</td> </tr> </table> </body> </html> As you would have noticed, the relationship i would like to see is a one to many relationship (1 DOMAIN can have many SKU which are rendered as a comma delimited string) Any help is appreciated. Thanks in advance... |
|
#2
|
|||
|
|||
|
One of topxml forum members helped me solve my problem. Here is the code that does the transformation
XSLT: ==== <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:key name="domains" match="record" use="column" /> <xsl:template match="/resultSet"> <html> <body> <table border="1"> <xsl:apply-templates select="record[count(.|key('domains',column)) = count(.)]" /> </table> </body> </html> </xsl:template> <xsl:template match="record"> <tr> <td><xsl:value-of select="column" /></td> <td> <xsl:for-each select="key('domains',current()/column)/column"> <xsl:value-of select="."/> <xsl:if test="position() != last()">,</xsl:if> </xsl:for-each> </td> </tr> </xsl:template> </xsl:stylesheet> |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > Converting a XML document to a HTML table with ',' delimiter |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|