xslt - Using nested XML data to display in HTML Table -


i transforming xml html table using xslt stuck on 1 point xml has multiple data below

<newdataset>     <table>         <rating>existing internal ratings</rating>         <financial_year>2011-12</financial_year>         <internal_rating>sb-7</internal_rating>         <validation_date>28.02.2017</validation_date>         <long_term_rating/>         <short_term_rating/>         <expiry_date/>         <rating_amount/>     </table>      <table>         <rating>previous internal ratings</rating>         <financial_year>2010-11</financial_year>         <internal_rating>sb-9</internal_rating>         <validation_date>25.02.2016</validation_date>         <long_term_rating/>         <short_term_rating/>         <expiry_date/>         <rating_amount/>     </table>     <table>         <rating>dynamic rating</rating>         <financial_year/>         <internal_rating>28.02.2017</internal_rating>         <validation_date/>         <long_term_rating/>         <short_term_rating/>         <expiry_date/>         <rating_amount/>     </table>     <table>         <rating>existing external ratings</rating>         <financial_year/>         <internal_rating/>         <validation_date/>         <long_term_rating>bbb+</long_term_rating>         <short_term_rating>b1</short_term_rating>         <expiry_date>31.03.2017</expiry_date>         <rating_amount>125</rating_amount>     </table>     <table>         <rating>previous external ratings</rating>         <financial_year/>         <internal_rating/>         <validation_date/>         <long_term_rating>a+</long_term_rating>         <short_term_rating>a2</short_term_rating>         <expiry_date>28.02.2016</expiry_date>         <rating_amount>212</rating_amount>     </table> </newdataset> 

to display data in table want fetch data xml on basis of rating tag. identifier present in xml data.

xslt using below

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform">     <xsl:output method="html" encoding="utf-8" indent="no"/>                     <xsl:template match="/">         <html>             <head>                 <!--<meta charset="utf-8" />-->                 <!--<title></title>-->                 <!--<style type="text/css">-->                 <style type="text/css"> .tg  {border-collapse:collapse;border-spacing:0;margin:0px auto;} .tg td{font-family:arial, sans-serif;font-size:14px;padding:3px 11px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;} .tg th{font-family:arial, sans-serif;font-size:14px;font-weight:normal;padding:3px 11px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;} .tg .tg-123c{font-weight:bold;font-family:"times new roman", times, serif !important;;vertical-align:top} .tg .tg-xnj0{font-weight:bold;font-family:"times new roman", times, serif !important;;background-color:#3166ff;text-align:center} .tg .tg-g145{font-family:"times new roman", times, serif !important;;text-align:center;vertical-align:top} .tg .tg-smzr{font-family:"times new roman", times, serif !important;;vertical-align:top} .tg .tg-gh1y{font-weight:bold;font-family:"times new roman", times, serif !important;;text-align:center;vertical-align:top} .tg .tg-20ea{font-weight:bold;font-family:"times new roman", times, serif !important;;background-color:#3531ff;text-align:center} .tg .tg-62yd{font-family:"times new roman", times, serif !important;;background-color:#ffffff}                 </style>             </head>             <body>                  <table class="tg">                     <tr>                         <th class="tg-20ea" colspan="3">internal ratings</th>                         <th class="tg-20ea">dynamic rating</th>                         <th class="tg-62yd" rowspan="6"/>                         <th class="tg-xnj0" colspan="3">external ratings</th>                     </tr>                     <tr>                         <td class="tg-smzr"/>                         <td class="tg-gh1y">existing</td>                         <td class="tg-gh1y">previous</td>                         <td class="tg-smzr" rowspan="2"/>                         <td class="tg-123c">agency</td>                         <td class="tg-gh1y">existing (care)</td>                         <td class="tg-gh1y">previous (crisil)</td>                     </tr>                     <tr>                         <td class="tg-gh1y">financial year</td>                         <td class="tg-g145">2011-12</td>                         <td class="tg-g145">2010-11</td>                         <td class="tg-123c">long term rating</td>                         <td class="tg-g145">bbb+</td>                         <td class="tg-g145">a+</td>                     </tr>                     <tr>                         <td class="tg-gh1y" rowspan="2">internal rating</td>                         <td class="tg-g145" rowspan="2">sb-7</td>                         <td class="tg-g145" rowspan="2">sb-9</td>                         <td class="tg-g145" rowspan="2">sb-7</td>                         <td class="tg-123c">short term rating</td>                         <td class="tg-g145">b1</td>                         <td class="tg-g145">a2</td>                     </tr>                     <tr>                         <td class="tg-123c">expiry date</td>                         <td class="tg-g145">31.03.2017</td>                         <td class="tg-g145">28.02.2016</td>                     </tr>                     <tr>                         <td class="tg-gh1y">validation date</td>                         <td class="tg-g145">28.02.2017</td>                         <td class="tg-g145">25.02.2016</td>                         <td class="tg-g145">31.03.2016</td>                         <td class="tg-123c">rating amount</td>                         <td class="tg-g145">125</td>                         <td class="tg-g145">212</td>                     </tr>                 </table>              </body>         </html>              </xsl:template>                      </xsl:stylesheet> 

i want dynamically change data not highlighted in bold in sample output image.

expected output : enter image description here

currently passing hard coded values in xslt present in input xml. is way fetch other tags data nested xml on basis of data present in specific tag? rating tag present in mentioned xml data.

i want below can in sql.

select financial_year table rating = 'first' select financial_year table rating = 'second' 

i tried fetch values in 1 of td below returning blank in output.

<tr>     <td class="tg-gh1y">validation date</td>     <td class="tg-g145">28.02.2017</td>     <td class="tg-g145">25.02.2016</td>     <td class="tg-g145">31.03.2016</td>     <td class="tg-123c">rating amount</td>     <td class="tg-g145">125</td>     <td class="tg-g145">         <xsl:value-of select="newdataset/table[rating = 'first']/internal_rating"/>     </td> </tr> 

using xslt expected output. if there suggestions let me know.

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform">     <xsl:output method="html" encoding="utf-8" indent="no"/>                     <xsl:template match="/">         <html>             <head>                 <!--<meta charset="utf-8" />-->                 <!--<title></title>-->                 <!--<style type="text/css">-->                 <style type="text/css"> .tg  {border-collapse:collapse;border-spacing:0;margin:0px auto;} .tg td{font-family:arial, sans-serif;font-size:14px;padding:3px 11px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;} .tg th{font-family:arial, sans-serif;font-size:14px;font-weight:normal;padding:3px 11px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;} .tg .tg-123c{font-weight:bold;font-family:"times new roman", times, serif !important;;vertical-align:top} .tg .tg-xnj0{font-weight:bold;font-family:"times new roman", times, serif !important;;background-color:#3166ff;text-align:center} .tg .tg-g145{font-family:"times new roman", times, serif !important;;text-align:center;vertical-align:top} .tg .tg-smzr{font-family:"times new roman", times, serif !important;;vertical-align:top} .tg .tg-gh1y{font-weight:bold;font-family:"times new roman", times, serif !important;;text-align:center;vertical-align:top} .tg .tg-20ea{font-weight:bold;font-family:"times new roman", times, serif !important;;background-color:#3531ff;text-align:center} .tg .tg-62yd{font-family:"times new roman", times, serif !important;;background-color:#ffffff}                 </style>             </head>             <body>                  <table class="tg">                     <tr>                         <th class="tg-20ea" colspan="3">internal ratings</th>                         <th class="tg-20ea">dynamic rating</th>                         <th class="tg-62yd" rowspan="6"/>                         <th class="tg-xnj0" colspan="3">external ratings</th>                     </tr>                     <tr>                         <td class="tg-smzr"/>                         <td class="tg-gh1y">existing</td>                         <td class="tg-gh1y">previous</td>                         <td class="tg-smzr" rowspan="2"/>                         <td class="tg-123c">agency</td>                         <td class="tg-gh1y">existing (care)</td>                         <td class="tg-gh1y">previous (crisil)</td>                     </tr>                     <tr>                         <td class="tg-gh1y">financial year</td>                         <td class="tg-g145"><xsl:value-of select="newdataset/table[rating = 'existing internal ratings']/financial_year"/></td>                         <td class="tg-g145"><xsl:value-of select="newdataset/table[rating = 'previous internal ratings']/financial_year"/></td>                         <td class="tg-123c">long term rating</td>                         <td class="tg-g145"><xsl:value-of select="newdataset/table[rating = 'existing external ratings']/long_term_rating"/></td>                         <td class="tg-g145"><xsl:value-of select="newdataset/table[rating = 'previous external ratings']/long_term_rating"/></td>                     </tr>                     <tr>                         <td class="tg-gh1y" rowspan="2">internal rating</td>                         <td class="tg-g145" rowspan="2"><xsl:value-of select="newdataset/table[rating = 'existing internal ratings']/internal_rating"/></td>                         <td class="tg-g145" rowspan="2"><xsl:value-of select="newdataset/table[rating = 'previous internal ratings']/internal_rating"/></td>                         <td class="tg-g145" rowspan="2"><xsl:value-of select="newdataset/table[rating = 'dynamic rating']/internal_rating"/></td>                         <td class="tg-123c">short term rating</td>                         <td class="tg-g145"><xsl:value-of select="newdataset/table[rating = 'existing external ratings']/short_term_rating"/></td>                         <td class="tg-g145"><xsl:value-of select="newdataset/table[rating = 'previous external ratings']/short_term_rating"/></td>                     </tr>                     <tr>                         <td class="tg-123c">expiry date</td>                         <td class="tg-g145"><xsl:value-of select="newdataset/table[rating = 'existing external ratings']/expiry_date"/></td>                         <td class="tg-g145"><xsl:value-of select="newdataset/table[rating = 'previous external ratings']/expiry_date"/></td>                     </tr>                     <tr>                         <td class="tg-gh1y">validation date</td>                         <td class="tg-g145"><xsl:value-of select="newdataset/table[rating = 'existing internal ratings']/validation_date"/></td>                         <td class="tg-g145"><xsl:value-of select="newdataset/table[rating = 'previous internal ratings']/validation_date"/></td>                         <td class="tg-g145"><xsl:value-of select="newdataset/table[rating = 'dynamic rating']/validation_date"/></td>                         <td class="tg-123c">rating amount</td>                         <td class="tg-g145"><xsl:value-of select="newdataset/table[rating = 'existing external ratings']/rating_amount"/></td>                         <td class="tg-g145"><xsl:value-of select="newdataset/table[rating = 'previous external ratings']/rating_amount"/></td>                     </tr>                 </table>              </body>         </html>              </xsl:template>                      </xsl:stylesheet> 

the following xpath expression corresponds sql statement have given example:

//table[rating = 'first']/financial_year 

applying input gives:

> xmllint --xpath "//table[rating = 'first']/financial_year" test.xml  <financial_year>2011-12</financial_year> 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -