2013-03-11 60 views
-1

有人可以幫我調試這個XSLT嗎?我不能花費太多時間,因爲本週我有很多事情要做,我一直在嘗試至少半個小時,但仍然無法找到問題所在。我在XSLT方面的技能是有限的,而且我們在課堂上所做的事情太多,另外,除了抱怨急性角色(á,é...)之外,Firefox並沒有太多幫助。Firefox無法解析XSLT,IE9只是忽略它,幫助調試?

這裏有一個pastie環節,主要是因爲該代碼是太大了:http://pastie.org/6452944

再次感謝!

回答

3

一個體面的XML編輯器,可能會告訴你有什麼問題:

  • 你有一個開口<table>標籤,你應該有一個結束</table>標籤。
  • &eq;在標準XML中沒有意義;你應該使用=
  • <xsl:choose>不允許select屬性
  • 是非法的結尾加上一個斜線的XPath。

和邏輯錯誤:

  • @observaciones = urgente@observaciones測試是否等於節點urgente(其不在這種情況下存在)。您需要使用@observaciones = 'urgente'

當這些問題得到解決後,我想它會起作用。這裏是一個固定的後續版本:

<xsl:stylesheet version="1.0" xmlns="http://www.w3.org/1999/xhtml" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:output method="html" omit-xml-declaration="yes"/> 

    <xsl:template match="/empresa"> 
    <html> 
     <head> 
     <title> 
      <xsl:value-of select="sede/nombre" /> 
     </title> 
     <link rel="stylesheet" href="empresa.css" /> 
     </head> 
     <body> 
     <table> 
      <tr class="titulo"> 
      <td> 
       <p> 
       <xsl:value-of select="sede/nombre" /> 
       </p> 
      </td> 
      <td rowspan="2"> 
       <img alt="empresa" src="empresa.png" /> 
      </td> 
      </tr> 

      <tr class="subtitulo"> 
      <td> 
       <p>Albaran</p> 
      </td> 
      </tr> 

      <xsl:apply-templates select="pedido"> 
      <xsl:sort select="@id" /> 
      </xsl:apply-templates> 
     </table> 
     </body> 
    </html> 
    </xsl:template> 

    <xsl:template match="pedido"> 
    <tr class="cuerpo"> 
     <td rowspan="3"> 
     <span> 
      <xsl:value-of select="sucursal/nombre" /> 
     </span> 
     <br /> 
     <span> 
      <xsl:value-of select="sucursal/region" /> 
     </span> 
     </td> 
    </tr> 

    <tr class="fecha"> 
     <td> 
     <p> 
      Albaran con fecha de: <xsl:value-of select="fecha" /> 
     </p> 
     </td> 
    </tr> 

    <tr class="npedido"> 
     <xsl:apply-templates select="@id" /> 
    </tr> 
    <tr class="articulos"> 
     <td> 
     <table> 
      <tr> 
      <th> 
       <span>Cod. de articulo</span> 
      </th> 
      <th> 
       <span>N. de unidades</span> 
      </th> 
      <th> 
       <span>Precio por unidad</span> 
      </th> 
      <th> 
       <span>Observaciones</span> 
      </th> 
      </tr> 
      <xsl:apply-templates select="articulo"> 
      <xsl:sort select="@id" /> 
      </xsl:apply-templates> 
     </table> 
     </td> 
    </tr> 

    <tr class="observaciones"> 
     <td> 
     <xsl:apply-templates select="@observaciones[. = 'urgente' or 
                . = 'incompleto']" /> 
     </td> 
    </tr> 
    </xsl:template> 

    <xsl:template match="articulo"> 
    <tr> 
     <xsl:apply-templates select="@id" /> 
     <xsl:apply-templates select="@cant" /> 
     <xsl:apply-templates select="@precioud" /> 
     <xsl:call-template name="Cell"> 
     <xsl:with-param name="value" select="@observaciones" /> 
     </xsl:call-template> 
    </tr> 
    </xsl:template> 

    <xsl:template match="articulo/@* | pedido/@id" 
       name="Cell"> 
    <xsl:param name="value" select="." /> 
    <td> 
     <span> 
     <xsl:value-of select="$value" /> 
     </span> 
    </td> 
    </xsl:template> 

    <xsl:template match="@observaciones"> 
    <strong> 
     <xsl:value-of select="concat(translate(substring(., 1, 1), 'it', 'IT'), 
            substring(., 2))"/> 
    </strong> 
    </xsl:template> 

</xsl:stylesheet> 
+0

我用記事本+ +作爲我的編輯器和新的一天工作這麼匆忙,因爲SQL考試(也就是今天,這比我想象的更容易)。無論如何,謝謝你指出錯誤,而不是糾正我的文件,有些東西是我的粗心,但大多數是我不明白的東西。 – Alxe 2013-03-12 11:42:54