2017-08-18 8 views
0

私はXSLTを使用してHTMLテーブルにXMLを変換するが、XMLは私が取得したいテーブル内のデータを表示するにはHTMLの表に表示するネストされたXMLデータを使用して

<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> 

以下のように複数のデータを持っている一点にこだわっています評価タグに基づいてXMLからのデータを取得します。これは、そのXMLデータに存在する唯一の識別子です。私は動的にサンプル出力画像に太字で強調表示されていないデータを変更したい

<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> 

以下のように私はこれを使用しています

XSLTです。

予想される出力: enter image description here

現在、私は、入力XMLに存在しているXSLTでハードコードされた値を渡しています。 特定のタグに存在するデータに基づいて、ネストされたXMLから他のタグデータを取得する方法はありますか?前述のXMLデータに存在するRatingタグに似ています。

私はSQLでできることを次のようにしたいと思います。

SELECT Financial_Year FROM Table WHERE Rating = 'First' 
SELECT Financial_Year FROM Table WHERE Rating = 'Second' 

Iは以下のようにtdのいずれかの値をフェッチしようとしたが、それは出力ブランク復帰されます。

<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> 

期待される出力を得るためにXSLTを使用する。何か提案があれば教えてください。

<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> 

答えて

0

次のXPath式を使用すると、一例として与えられていたSQL文に対応:

//Table[Rating = 'First']/Financial_Year 

あなたの入力にこれを適用することができます:

> xmllint --xpath "//Table[Rating = 'First']/Financial_Year" test.xml 
<Financial_Year>2011-12</Financial_Year> 
+0

は、以下の使用してXSLTで、この作業を行いますコマンド。​​

+0

原則はyesですが、結果として得られるHTMLをどのように表示するかによって異なります。結果をどのように正確に表示するかの例で質問を更新してください。これまでに試したことも示してください。 – Markus

+0

表示したいデータに大きなテーブルがあります。私は同じものの小さな部分を使用して質問した質問。現在は、​​ 'を使用して特定のデータを選択しようとしました。 –

関連する問題