2017-02-14 115 views
0
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:output method="xml" encoding="utf-8" indent="yes"/> 
<xsl:variable name="cdataStart"><![CDATA[ <![CDATA ]]></xsl:variable> 
<xsl:variable name="cdataEnd"><![CDATA[ ]] ]]></xsl:variable> 
<xsl:template match="/Prekes"> 
    <products> 
     <xsl:for-each select="./product"> 
      <product> 
        <associations> 
         <association external-reference="<xsl:value-of select="./code" />"> 
          <mode>replace</mode> 
         </association> 
        </associations> 
       </block> 
      </product> 
     </xsl:for-each> 
    </products> 
</xsl:template> 

XSL值屬性

我需要把我的價值從進入外部基準的屬性。問題是如果我嘗試像這樣使用它,我會得到語法錯誤。我怎樣才能適當地插入它?

回答

3

這裏需要使用Attribute Value Templates ...

<association external-reference="{code}"> 

大括號指示要計算的表達式,而不是字面直接輸出。

注意,您可以使用xsl:attribute這裏也

<association> 
    <xsl:attribute name="external-reference"> 
     <xsl:value-of select="./code" /> 
    </xsl:attribute> 

但正如你所看到的,屬性值模板是更簡潔。例如,您希望在有條件地創建屬性的情況下使用xsl:attribute

+0

謝謝你,花括號沒有幫助。但是我將這個屬性用作xsl:atribute。 – The50