2010-12-14 22 views
0

我有一個奇怪的項目,我想通過我的XSLT轉換,通過一個XML文件枚舉,但是我後爲每個循環放入代碼我記錄沒有拉動任何細節(已經)。幫幫我!XSLT爲每個無法拾取字段

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'子元素。 – 2010-12-14 15:53:01

回答

4

<xsl:for-each select="item"> - 我認爲你在 「項目」 是已。你不能再選擇它。

+0

Doh!感謝那。 – wonea 2010-12-14 16:15:47

0

你已經有一個item模板 - 你爲什麼需要for-each裏面呢?

我預計這會失敗,因爲item節點不包含item節點。