2010-12-14 8 views
0

私は興味深いアイテムがあります。私はXSLT変換でXMLファイルを列挙しようとしていますが、for-eachループをコードに入れてしまいました。レコードは詳細を引き出すことはありません(これ以上)。助けて!XSLT for eachがフィールドを取得できません

XSLT

<?xml version="1.0" encoding="utf-8"?> 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> 
    <xsl:output method="html" indent="yes" omit-xml-declaration="yes"/> 
    <xsl:variable name="pathid" select="montage/path" /> 
    <xsl:variable name="outputstr" select="''" /> 
    <xsl:template match="vista"> 
     <xsl:variable name="pathid" select="path" /> 
     <html> 
      <body> 
       <div align="center"> 
        <table border="0" cellpadding="0" cellspacing="0" width="800" height="200"> 
         <xsl:apply-templates select="item" /> 
        </table> 
       </div> 
      </body> 
     </html> 
    </xsl:template> 
    <xsl:template match="item"> 
     <xsl:variable name="monid" select="mon" /> 
      <!--<xsl:value-of select="format-number(position(), '#')" />--> 
     <xsl:variable name="outputstr" select="file" /> 
      <xsl:choose> 
       <xsl:when test="position() >= 0 and 4 > position()"> 
        <tr height="200"> 
        <xsl:for-each select="item"> 
         <td width="157" height="108" valign="top"> 
          <xsl:attribute name="height"> 
           <xsl:value-of select="'200'"/> 
          </xsl:attribute> 
          <a> 
           <xsl:attribute name="href"> 
            <xsl:value-of select="$pathid" /> 
            <xsl:value-of select="thepage" /> 
           </xsl:attribute> 
           <img> 
            <xsl:attribute name="src"> 
             <xsl:value-of select="concat(substring-before($outputstr,'abc'),$pathid)"/> 
             <xsl:value-of select="$outputstr" /> 
            </xsl:attribute> 
           </img> 
          </a> 
         </td> 
         </xsl:for-each> 
        </tr> 
       </xsl:when> 
      </xsl:choose> 
      <xsl:attribute name="id">mon</xsl:attribute> 
    </xsl:template> 
</xsl:stylesheet> 

XML

<?xml version="1.0"?> 
<vista> 
    <lastupdate>14/12/2010 14:32</lastupdate> 
    <path>C:\</path> 
    <item> 
     <thepage>00000657.html</thepage> 
     <heading>heading1</heading> 
     <file>test123.png</file> 
     <description>df bhdf hdfhdf hdfh he rher herh df bdf bdfb df rfbd bd</description> 
    </item> 
    <item> 
     <thepage>00000660.html</thepage> 
     <heading>heading2</heading> 
     <file>test456.jpg</file> 
     <description>reh erh erherh erh erher herh</description> 
    </item> 
</vista> 

出力HTML

<html> 
<body> 
<div align="center"> 
<table border="0" cellpadding="0" cellspacing="0" width="800" height="200"> 
<tr height="200"></tr> 
<tr height="200"></tr> 
<tr height="200"></tr> 
<tr height="100"></tr> 
<tr height="100"></tr> 
<tr height="100"></tr> 
<tr height="100"></tr> 
</table> 
</div> 
</body> 
</html> 
+0

あなたが 'item'要素にマッチしている場合、入力ソースに' item'の 'item'子がないので、' item'子に対する反復は間違っています。 –

答えて

4

ライン<xsl:for-each select="item"> - 私はあなたが "アイテム" で、すでにだと思います。もう一度選択することはできません。

+0

Doh!ありがとうございました。 – wonea

0

あなたはすでにitemテンプレートを持っていますが、その中にfor-eachが必要なのはなぜですか?

ノードがitemノードを含まないため、itemノードには失敗すると予想します。

関連する問題