xml - XSLT html mixed table body -
i have sample xml needs rendered html. when obx.5 greater 20 characters, want show in paragraph other wise atomic values of same need clubbed table. tried xsl below, produces empty table , nothing in paragraph. should corrected in xsl desired output? want assign table header. how detect obx.5 free-text(>30) or atomic type , setup table in xslt?
xml file
<?xml version="1.0" encoding="utf-8"?> <oru.orc_obr__obx_nte> <obx> <obx.5>negative specific anti-\.br\human haemoglobin antibody method.\.br\this suggests proximal g.i.t. bleed or diet/drug interference.\</obx.5> </obx> <obx> <obx.5>no salmonella, shigella, campylobacter or yersinia isolated</obx.5> </obx> <obx> <obx.5>throat</obx.5> </obx> <obx> <obx.5>negative</obx.5> </obx> <obx> <obx.5>129</obx.5> </obx> </oru.orc_obr__obx_nte>
xslt file
<?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:template match="/"> <html> <body> <table border="1"> <tr bgcolor="#9acd32"> <th>obx.5</th> </tr> <xsl:for-each select="oru.orc_obr__obx_nte/obx"> <xsl:variable name="result"> <b><xsl:value-of select="obx.5"/></b> </xsl:variable> <xsl:choose> <xsl:when test="string-length($result) < 30"> <tr><td bgcolor="#ff00ff"> <xsl:value-of select="$result"/> </td> </tr> </xsl:when> <xsl:otherwise> <p class="notes"> <xsl:value-of select="$result"/> <br/> </p> </xsl:otherwise> </xsl:choose> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet>
html is
<html> <body> <table border="1"> <tr bgcolor="#9acd32"> <th>obx.5</th> </tr> <p class="notes">negative specific anti-\.br\human haemoglobin antibody method.\.br\this suggests proximal g.i.t. bleed or diet/drug interference.\<br></p> <p class="notes">no salmonella, shigella, campylobacter or yersinia isolated<br></p> <tr> <td bgcolor="#ff00ff">throat</td> </tr> <tr> <td bgcolor="#ff00ff">negative</td> </tr> <tr> <td bgcolor="#ff00ff">129</td> </tr> </table> </body> </html>
html want result is
<html> <body> <p class="notes">negative specific anti-\.br\human haemoglobin antibody method.\.br\this suggests proximal g.i.t. bleed or diet/drug interference.\<br></p> <p class="notes">no salmonella, shigella, campylobacter or yersinia isolated<br></p> <table border="1"> <tr bgcolor="#9acd32"> <th>obx.5</th> </tr> <tr> <td bgcolor="#ff00ff">throat</td> </tr> <tr> <td bgcolor="#ff00ff">negative</td> </tr> <tr> <td bgcolor="#ff00ff">129</td> </tr> </table> </body> </html>
additional examples: input xml
<?xml version="1.0" encoding="utf-8"?> <oru.orc_obr__obx_nte> <obx> <obx.5>negative specific anti-\.br\human haemoglobin antibody method.\.br\this suggests proximal g.i.t. bleed or diet/drug interference.\</obx.5> </obx> <obx> <obx.5>no salmonella, shigella, campylobacter or yersinia isolated</obx.5> </obx> <nte> <nte.3>after 5 dots carat.....^\.br\</nte.3> </nte> <obx> <obx.5>throat</obx.5> </obx> <obx> <obx.5>negative</obx.5> </obx> <obx> <obx.5>yersinia isolated</obx.5> </obx> <nte> <nte.3>after 5 dots carat.....^\.br\</nte.3> </nte> <obx> <obx.5>129</obx.5> </obx> <obx> <obx.5>129</obx.5> </obx> <obx> <obx.5>130</obx.5> </obx> <obx> <obx.5>131</obx.5> </obx> <obx> <obx.5>132</obx.5> </obx> <nte> <nte.3>after 5 dots carat.....^\.br\</nte.3> </nte> </oru.orc_obr__obx_nte>
output html
<html> <body> <p class="notes"> negative specific anti-\.br\human haemoglobin antibody method.\.br\this suggests proximal g.i.t. bleed or diet/drug interference.\ <br></p> <p class="notes"> no salmonella, shigella, campylobacter or yersinia isolated <br></p> <p class="footnote"> after 5 dots carat.....^\.br\ <br></p> <table border="1"> <tr bgcolor="#9acd32"> <th>obx.5</th> </tr> <tr> <td bgcolor="#ff00ff"> throat </td> </tr> <tr> <td bgcolor="#ff00ff"> negative </td> </tr> <tr> <td bgcolor="#ff00ff"> yersinia isolated </td> </tr> </table> <p class="footnote"> after 5 dots carat.....^\.br\ <br></p> <table border="1"> <tr bgcolor="#9acd32"> <th>obx.5</th> </tr> <tr> <td bgcolor="#ff00ff"> 129 </td> </tr> <tr> <td bgcolor="#ff00ff"> 129 </td> </tr> <tr> <td bgcolor="#ff00ff"> 130 </td> </tr> <tr> <td bgcolor="#ff00ff"> 131 </td> </tr> <tr> <td bgcolor="#ff00ff"> 132 </td> </tr> </table> <p class="footnote"> after 5 dots carat.....^\.br\ <br></p> </body> </html>
the following stylesheet:
xslt 1.0
<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/> <xsl:template match="/"> <html> <body> <xsl:apply-templates select="oru.orc_obr__obx_nte/obx[string-length(.) >= 30]" mode="p"/> <table border="1"> <tr bgcolor="#9acd32"> <th>obx.5</th> </tr> <xsl:apply-templates select="oru.orc_obr__obx_nte/obx[string-length(.) < 30]" mode="tr"/> </table> </body> </html> </xsl:template> <xsl:template match="obx" mode="p"> <p class="notes"> <xsl:value-of select="."/> <br/> </p> </xsl:template> <xsl:template match="obx" mode="tr"> <tr> <td bgcolor="#ff00ff"> <xsl:value-of select="."/> </td> </tr> </xsl:template> </xsl:stylesheet>
will return required result in example case. said in comments, not sure want when short , long values interspersed.
note table created without checking if short values exist - might want add yourself.
Comments
Post a Comment