2016-11-04 34 views
1

我正在開發一個CMS功能,用戶可以將元數據添加到圖像。 Option源用於創建到原始資源/主頁的反向鏈接。在XSLT 1.0中刪除http(s)://

這種情況下工作finder來確定一個鏈接應顯示或只是資源。

但我從a href鏈路去除的http(s)://問題,因爲這看起來並不好(存儲在$image_source)鏈接IST。

可悲的是,XSLT 1.0不支持replace()方法。

對此有任何簡單的解決方法?否則,我可以選擇將與substring-after()一個更大的模板。

<xsl:if test="$image_source!=''"> 
    <xsl:choose> 
    <xsl:when test="starts-with($image_source, 'http://') or starts-with($image_source ,'https://')"> 
      <span class="image-meta-source"> 
       <a href="{$image_source}" title="{$image_title}"> 
       <xsl:value-of select="$image_source"/> 
       </a> 
      </span> 
    </xsl:when> 
    <xsl:otherwise> 
     <span class="image-meta-source"><xsl:value-of select="$image_source"/></span> 
    </xsl:otherwise> 
    </xsl:choose> 
</xsl:if> 

通常情況下,我會使用正則表達式她e但afaik在XSLT 1.0中不支持(如許多有用的功能)。我能想到的一個正則表達式是^(http|https)://雖然有機會使用它嗎?

+0

你不能只是做'子,後($ image_source, '//')'吧? –

+0

@TimC是的,看到邁克爾的回答。我真的不知道爲什麼我試圖讓這個複雜。 – TechTreeDev

回答

3

您可以使用類似:

<xsl:when test="starts-with($image_source, 'http://') or starts-with($image_source ,'https://')"> 
    <xsl:value-of select="substring-after($image_source, '://')"/> 
</xsl:when> 
+0

您好,先生,是天才,我是白癡:D非常感謝,我從來沒有想過這樣一個簡單的解決方案 – TechTreeDev