2014-10-08 77 views
0

出來我想獲取當前元素名稱,但它顯示另一個文檔名稱的名稱。如何獲取當前文檔元素,而不是另一個文檔元素名稱?,這只是示例編碼,不要將「獲取名稱」的建議用於每個。特別是我喜歡進入每個循環從另一個文檔(),xslt

<xsl:template match="*:LegisRefLink"> 
    <xsl:element name="LegiRefered" namespace="http://www.w3.org/1999/xhtml"> 
     <xsl:variable name="legs" select="document(@href)//*"/> 
     <xsl:for-each select="$legs//*:ref"> 
     <xsl:value-of select="name(.)"/>// I would like to get current document element name, but it's showing $legis/ref. how to get current element instead of another document element name. 
     <xsl:value-of select="@refNo"/> 
     </xsl:for-each> 
    </xsl:element> 
    </xsl:template> 

請幫助我實現這一目標!感謝Advances!

問候, 薩蘭

回答

0

經常在XSL,有現任和前任的上下文之間的衝突。這些通常必須與變量解析爲保持過去的狀態的情況下:

<xsl:template match="*:LegisRefLink"> 
    <xsl:element name="LegiRefered" namespace="http://www.w3.org/1999/xhtml"> 
     <!-- Could save "." and get the name within the loop but if that's all we want, keep it efficient. --> 
     <xsl:variable name="refName" select="name(.)"/> 
     <xsl:variable name="legs" select="document(@href)//*"/> 
     <xsl:for-each select="$legs//*:ref"> 
     <xsl:value-of select="$refName"/>  <!-- Use the value saved earlier when we did have the correct context. --> 
     <xsl:value-of select="@refNo"/> 
     </xsl:for-each> 
    </xsl:element> 
    </xsl:template> 

注意,它使用相同的語法與您加載的文件 - 一個變量(XSL不會讓你改變)只是保存特定節點,結果或價值的一種方式。

+0

非常感謝 – 2014-10-08 09:23:28

相關問題