2017-01-27 53 views
0

下面的模板固定img/src屬性,並在那裏,因爲年:二XSL模板禁用第一個

<xsl:template match="xh:img/@src"> 
    <xsl:attribute name="src"> 
     <xsl:value-of select=" 
      if(string-length(substring-before(substring-after(
       subsequence(parent::node()/following-sibling::comment(),1,1),'src=&quot;'),'.eps')) > 0) 
      then 
       concat('images/',tokenize(concat(substring-before(substring-after(
        subsequence(parent::node()/following-sibling::comment(),1,1),'src=&quot;'),'.eps'),'.png'),'/')[last()]) 
      else 
       data(self::node())"/> 
    </xsl:attribute> 
</xsl:template> 

現在我加入了下面的模板移動widthheightstyle

<xsl:template match="xh:img"> 
    <img style="width:{@width}; height:{@height};"> 
     <xsl:copy-of select="@*[not(name()='width' or name()='height')]"/> 
    </img> 
</xsl:template> 

第二個工作,但它「禁用」第一個。 如果我評論第二個,第一個作品。 有沒有合併它們的方法?

我真的沒有XSL的經驗,所以任何幫助,將不勝感激。

回答

2

這是因爲您正在使用xsl:copy-of複製匹配xh:img的模板中的屬性。這不會應用任何匹配的模板,而只是完全複製它們。

只要切換到使用xsl:apply-templates ...

<xsl:apply-templates select="@*[not(name()='width' or name()='height')]"/> 

但是,您可能需要添加額外的模板匹配比src如果您希望仍然過於創建它們的其他屬性。

<xsl:template match="@*"> 
    <xsl:copy /> 
</xsl:template> 
+0

這很簡單嗎?我試圖合併它們......謝謝,它完美的工作! – marco

相關問題