2013-07-15 33 views
0

我有一些XSLT,它試圖爲圖像添加一個URL。到目前爲止,我已經使用XSLT將圖像添加到圖像

<xsl:if test="$currentPage/ImageOne != ''"> 

     <xsl:element name="img"> 
     <xsl:attribute name="src"> 
      <xsl:value-of select="umbraco.library:GetMedia($currentPage/ImageOne, 0)/*"/> 
     </xsl:attribute> 

     <xsl:attribute name="alt"> 
      <xsl:value-of select="$currentPage/ImageOne"/> 
     </xsl:attribute> 
     </xsl:element> 

    </xsl:if> 

如果我再添XSLT節點

 <xsl:attribute name="a"> 
      <xsl:value-of select="http://somesite.com"/> 
     </xsl:attribute> 
     </xsl:element> 

然後我得到一個解析器錯誤(在使用「一」,以超鏈接添加到圖片上面的代碼IM,但沒有任何工程。可能有人建議什麼問題呢?

感謝

新代碼

<xsl:if test="$currentPage/ImageOne != ''"> 

     <xsl:element name="a"> 
     <xsl:element name="img"> 
     <xsl:attribute name="src"> 
      <xsl:value-of select="umbraco.library:GetMedia($currentPage/ImageOne, 0)/*"/> 
     </xsl:attribute> 

     <xsl:attribute name="alt"> 
      <xsl:value-of select="$currentPage/ImageOne"/> 
     </xsl:attribute> 

     <xsl:element name="href"> 
      <xsl:value-of select="'http://www.microsoft.com'"/> 
     </xsl:element> 
     </xsl:element> 
     </xsl:element> 
    </xsl:if> 
+0

你幾點解析錯誤? –

+0

你在哪裏添加它? –

回答

0

如果您要添加的修補程序URL:"http://somesite.com"作爲屬性a 的值,並且使用xsl:value-of select你必須把「常量」串入撇號('..'

嘗試:

<xsl:attribute name="a"> 
      <xsl:value-of select="'http://somesite.com'"/> 
     </xsl:attribute> 
     </xsl:element> 

而且你並不需要在你的例子來使用xsl:element: 下可以做的一樣好:

<img a="http://somesite.com" alt="{$currentPage/ImageOne}"> 
     <xsl:attribute name="src"> 
      <xsl:value-of select="umbraco.library:GetMedia($currentPage/ImageOne, 0)/*"/> 
     </xsl:attribute> 
</img> 

要與圖像嘗試鏈接:

<a href="http://somesite.com" "> 
<img alt="{$currentPage/ImageOne}"> 
     <xsl:attribute name="src"> 
      <xsl:value-of select="umbraco.library:GetMedia($currentPage/ImageOne, 0)/*"/> 
     </xsl:attribute> 
    </img> 
</a> 
+0

因爲我沒有進一步解析器錯誤,所以我改變了代碼。 我已經改變了代碼(見上面的新代碼),但我不能讓它按預期工作(顯示和圖像有一個超鏈接到外部網站) 有沒有進一步的想法? 感謝 – Computer

+0

請首先考慮您的html最終應該是什麼樣子。此刻,您將一個'href'屬性添加到'img'。哪些劑量根本沒有意義。嘗試移動img元素上方的href屬性。 –

+0

謝謝。你發佈的代碼沒有用。我不知道這是否是由於我使用Umbraco或不是,但我想我需要遵循「新代碼」標題下的標準? – Computer