html - xslt rotate xml table conundrum -
i know shouldn't hard, i'm still bit of novice @ xslt. i've got xml file schema this:
<xs:element id="all_data"> <xs:complextype> <xs:element name="input_report"> <xs:complextype> <xs:element name="value_name"></xs:element> <xs:element name="value_date"></xs:element> <xs:element name="value_fame"></xs:element> <xs:element name="value_glory"></xs:element> <xs:element name="value_golden_stars"></xs:element> </xs:complextype> </xs:element> </xs:complextype> </xs:element>
the xml file looks (abbreviated):
<all_data> <input_report> <value_name>bob painter</value_name> <value_fame>nobody</value_fame> </input_report> <input_report> <value_name>norman normal</value_name> <value_fame>somebody</value_fame> <value_glory>sunny</value_glory> <value_golden_star>somebody</value_golden-star> </input_report> </all_data>
the tricky part i'm trying display html table so
value_name bob painter norman normal value_date value_fame nobody value_glory sunny value_golden_stars
i found code printing default values can create blanks, doesn't help me print row if none of reports have data. ideas?
<xsl:variable name="show_comments"> <xsl:choose> <xsl:when test="//query_string/show_comments"><xsl:value-of select="//query_string/show_comments"/></xsl:when> <xsl:otherwise>0</xsl:otherwise> <!-- default value --> </xsl:choose> </xsl:variable>
the next transformation prints row if none of reports have value:
<html xmlns:xsl="http://www.w3.org/1999/xsl/transform" xsl:version="2.0"> <head><title>all data</title></head> <body> <table> <tr> <td>value_name</td> <xsl:for-each select="//input_report"> <td><xsl:value-of select="value_name"/></td> </xsl:for-each> </tr> <tr> <td>value_date</td> <xsl:for-each select="//input_report"> <td> <xsl:choose> <xsl:when test="value_date"> <xsl:value-of select="value_date"/> </xsl:when> <xsl:otherwise>_nodate_</xsl:otherwise> </xsl:choose> </td> </xsl:for-each> </tr> <tr> <td>value_fame</td> <xsl:for-each select="//input_report"> <td> <xsl:choose> <xsl:when test="value_fame"> <xsl:value-of select="value_fame"/> </xsl:when> <xsl:otherwise>_nofame_</xsl:otherwise> </xsl:choose> </td> </xsl:for-each> </tr> <tr> <td>value_glory</td> <xsl:for-each select="//input_report"> <td> <xsl:choose> <xsl:when test="value_glory"> <xsl:value-of select="value_glory"/> </xsl:when> <xsl:otherwise>_noglory_</xsl:otherwise> </xsl:choose> </td> </xsl:for-each> </tr> <tr> <td>value_golden_stars</td> <xsl:for-each select="//input_report"> <td> <xsl:choose> <xsl:when test="value_golden_star"> <xsl:value-of select="value_golden_star"/> </xsl:when> <xsl:otherwise>_nostar_</xsl:otherwise> </xsl:choose> </td> </xsl:for-each> </tr> </table> </body> </html>
note did transformation on xml:
<?xml version="1.0" encoding="utf-8"?> <all_data> <input_report> <value_name>bob painter</value_name> <value_fame>nobody</value_fame> </input_report> <input_report> <value_name>norman normal</value_name> <value_fame>somebody</value_fame> <value_glory>sunny</value_glory> <value_golden_star>somebody</value_golden_star> </input_report> </all_data>
the input contained few typos, didn't know use. transformation need should similar.
html table xslt
No comments:
Post a Comment