xml - xsl template table issue -
i attempting apply xsl stylesheet xml file following instructions on w3schools , other sites confounded issue having. have multiple templates, basic 1 work fine tables screwy. headers repeating each row, apparently creating new tables each. small sample below. can tell me going wrong?
xsl
<xsl:output method="html"/> <xsl:template match="/"> <html> <body> <h2>site visit form</h2> <xsl:apply-templates/> </body> </html> </xsl:template> <xsl:template match="sitevisitform"> <p> <xsl:apply-templates select="sitevisit"/> <xsl:apply-templates select="field"/> </p> </xsl:template> <xsl:template match="sitevisit"> <p> site visit code: <span style="color:#ff0000"> <xsl:value-of select="sitevisitcode"/> </span> project id: <span style="color:#ff0000"> <xsl:value-of select="project_id"/> <xsl:value-of select="newproject"/> </span> <br /> personnel:<span style="color:#ff0000"> <xsl:value-of select="personnel"/> </span> </p> </xsl:template> <xsl:template match="field"> <table border="1"> <tr bgcolor="#9acd32"> <th>charactistic name</th> <th>result value</th> <th>unit</th> <th>analytical method</th> <th>result comment</th> </tr> <tr> <td><xsl:value-of select="characteristic_name"/></td> <td><xsl:value-of select="result_value"/></td> <td><xsl:value-of select="result_value_unit"/></td> <td><xsl:value-of select="analytical_method"/></td> <td><xsl:value-of select="result_comment"/></td> </tr> </table> </xsl:template>
xml
<sitevisit> <sitevisitcode>test</sitevisitcode> <project_id>flat-still-tpa</project_id> <newproject></newproject> <personnel>andersen, laura,apfelbeck, randy,arroues, pamela</personnel> </sitevisit> <field> <characteristic_name>temperature, water</characteristic_name> <result_value>12</result_value> <result_value_unit>deg c</result_value_unit> </field> <field> <characteristic_name>temperature, air</characteristic_name> <result_value>60</result_value> <result_value_unit>deg f</result_value_unit> </field> <field> <characteristic_name>specific conductance</characteristic_name> <result_value>122</result_value> <result_value_unit>us/cm</result_value_unit> </field> <field> <characteristic_name>ph</characteristic_name> <result_value>123</result_value> <result_value_unit>none</result_value_unit> </field>
you have declare "table" , "tr" once in template "sitevisitform", , apply-templates "field" after defining "tr":
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/xsl/transform" version="2.0"> <xsl:strip-space elements="*"/> <xsl:output method="html"/> <xsl:template match="/"> <html> <body> <h2>site visit form</h2> <xsl:apply-templates/> </body> </html> </xsl:template> <xsl:template match="sitevisitform"> <p> <xsl:apply-templates select="sitevisit"/> <table border="1"> <tr bgcolor="#9acd32"> <th>charactistic name</th> <th>result value</th> <th>unit</th> <th>analytical method</th> <th>result comment</th> </tr> <xsl:apply-templates select="field"/> </table> </p> </xsl:template> <xsl:template match="sitevisit"> <p> site visit code: <span style="color:#ff0000"> <xsl:value-of select="sitevisitcode"/> </span> project id: <span style="color:#ff0000"> <xsl:value-of select="project_id"/> <xsl:value-of select="newproject"/> </span> <br /> personnel:<span style="color:#ff0000"> <xsl:value-of select="personnel"/> </span> </p> </xsl:template> <xsl:template match="field"> <tr> <td> <xsl:value-of select="characteristic_name"/> </td> <td> <xsl:value-of select="result_value"/> </td> <td> <xsl:value-of select="result_value_unit"/> </td> <td> <xsl:value-of select="analytical_method"/> </td> <td> <xsl:value-of select="result_comment"/> </td> </tr> </xsl:template> </xsl:stylesheet>
Comments
Post a Comment