2011-08-11 14 views
1

次のXMLコードがあり、XSLTを使用して表示しようとしています。フィールド名を選択してテーブル内のすべての値を返す方法。私はしようとしたが、それは動作しません、ちょうど最初のレコード( 'ユーザー名'と 'ユーザー')を返します。助けてください、多くのありがとう。XSLT同じノード内の同じフィールド名の乗算値を選択して表示

XMLコード

<?xml version="1.0" encoding="utf-8"?> 
<?xml-stylesheet type="text/xsl" href="xml_list_new.xsl"?> 
<root> 
    <record> 
    <fieldname>username</fieldname> 
     <value>user</value> 
    <fieldname>ipaddress</fieldname> 
     <value>127.0.0.1</value> 
    <fieldname>lastaction</fieldname> 
     <value>2011-06-13 00:53:05</value> 
    <fieldname>sessionid</fieldname> 
     <value>h0atrutpu5vgrvuf3ipledfbvl1</value> 
    </record> 
    <record> 
    <fieldname>username</fieldname> 
     <value>admin</value> 
    <fieldname>ipaddress</fieldname> 
     <value>127.0.0.1</value> 
    <fieldname>lastaction</fieldname> 
     <value>2011-06-12 00:43:53</value> 
    <fieldname>sessionid</fieldname> 
     <value>nnbdofsdq4sd7e3def3hnid9</value> 
    </record> 
    <record> 
    <fieldname>username</fieldname> 
     <value>ccm</value> 
    <fieldname>ipaddress</fieldname> 
     <value>127.0.0.1</value> 
    <fieldname>lastaction</fieldname> 
     <value>2011-06-10 00:30:22</value> 
    <fieldname>sessionid</fieldname> 
     <value>di34bndffgrt48cmkl08d8e4</value> 
    </record> 
</root> 

XSLTコード

<?xml version='1.0'?> 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> 
<xsl:output method='html'/> 
<xsl:param name="title">XML List</xsl:param> 
<xsl:template match="/"> 
<html> 
<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> 
    <title><xsl:value-of select="$title"/></title> 
    <style type="text/css"> 
     <![CDATA[ 

      caption { font-weight: bold; } 
      th { 
      background: #2C3033; 
      color: #fff; 
      font-family: arial; 
      font-weight: bold; 
      font-size: 12px; 
      } 
      tr { 
      font-family: arial; 
      color: #000; 
      font-size: 12px; 
      background: #E0E0E0; 
      } 

     ]]> 
    </style> 
</head> 
<body> 
    <div class="center" style="width: 800px; margin: 0 auto"> 
    <table border="0" style="width: 800px"> 
     <caption><xsl:value-of select="$title"/></caption> 
     <thead> 
      <tr> 
       <xsl:for-each select="root/record"> 
       <th > 
       <xsl:value-of select="fieldname"/> 
       </th> 
      </xsl:for-each> 
      </tr> 
     </thead> 

     <tbody> 
     <xsl:for-each select="root/record"> 
     <tr> 
      <td ><xsl:value-of select="value"/></td> 
     </tr> 
     </xsl:for-each> 
     </tbody> 
    </table> 
    </div> 
</body> 
</html> 
</xsl:template> 
</xsl:stylesheet> 

答えて

0

は、このテンプレートを見てください。私はできるだけあなたのテンプレートに従いました。私は単一のテンプレートを追加しました(読みやすさのために出力を整理しました)。

[XSTL 1.0]

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:output indent="yes"/> 

    <xsl:template match="/"> 
     <table> 
      <thead> 
       <tr> 
        <xsl:for-each select="root/record[1]/fieldname"> 
         <th> 
          <xsl:value-of select="."/> 
         </th> 
        </xsl:for-each> 
       </tr> 
      </thead> 
      <tbody> 
       <xsl:for-each select="root/record"> 
        <tr> 
         <xsl:apply-templates select="value"/> 
        </tr> 
       </xsl:for-each> 
      </tbody>  
     </table> 
    </xsl:template> 

    <xsl:template match="value"> 
     <td> 
      <xsl:value-of select="."/> 
     </td> 
    </xsl:template> 

</xsl:stylesheet> 

次の表生成:

<table> 
    <thead> 
     <tr> 
     <th>username</th> 
     <th>ipaddress</th> 
     <th>lastaction</th> 
     <th>sessionid</th> 
     </tr> 
    </thead> 
    <tbody> 
     <tr> 
     <td>user</td> 
     <td>127.0.0.1</td> 
     <td>2011-06-13 00:53:05</td> 
     <td>h0atrutpu5vgrvuf3ipledfbvl1</td> 
     </tr> 
     <tr> 
     <td>admin</td> 
     <td>127.0.0.1</td> 
     <td>2011-06-12 00:43:53</td> 
     <td>nnbdofsdq4sd7e3def3hnid9</td> 
     </tr> 
     <tr> 
     <td>ccm</td> 
     <td>127.0.0.1</td> 
     <td>2011-06-10 00:30:22</td> 
     <td>di34bndffgrt48cmkl08d8e4</td> 
     </tr> 
    </tbody> 
</table> 
+0

はありがとうを、コードが作業を行いますが、私はそれが改行なしで表示する別の問題、との頭を持ってXMLのレコードセット数で複製されたテーブル。この問題を解決するには、ありがとう。 –

+0

私が欲しいのは、このような頭部を持つ普通のテーブルです。 '

\t \t \t \t \t \t \t \t \t​​ユーザー \t \t​​127.0.0.1 \t \t​​2011-06-13午後12時53分05秒 \t \t​​h0atrutpu5vgrvuf3ipledfbvl1 \t \t \t \t​​管理 \t \t​​127.0.0.1 \t \t​​2011年6月12日午後12時43分53秒 \t \t​​nnbdofsdq4sd7e3def3hnid9 \t \t \t \t​​CCM \t \t​​127.0.0。1 \t \t​​2011-06-10午後12時30分22秒 \t \t​​di34bndffgrt48cmkl08d8e4 \t \t
ユーザ名 ipaddressに lastactionセッションID
' –

+0

申し訳ありませんが、私は私が見るポスト –

関連する問題