2015-11-24 74 views
0

我有下面的XML,需要轉換它。xsl中的foreach循環

XML:<Assessment> 
     <Section ID="Listening">24</Section> 
     <Section ID="Writing">10</Section>  
     <Section ID="Reading">30</Section> 
     <Section ID="ABC">22</Section> 
    </Assessment> 

輸出:

Listening-24 
Writing-10 
Reading-30 
ABC-22 

我曾嘗試下面的代碼,但我不能夠得到評估的得分輸出。 我如何獲得評估中的價值?

XSL:

enter code here 
<xsl:for-each select="Assessment/Section"> 
       <xsl:value-of select="@ID"></xsl:value-of> 
       <xsl:value-of select="$delimiter"></xsl:value-of> 
       <xsl:value-of select="Section"></xsl:value-of> 
       <xsl:value-of select="$linefeed"></xsl:value-of> 
</xsl:for-each> 

請提供幫助,解決這個問題的代碼。

+0

請發表您的** **整體樣式,用變量的定義。 –

+0

是的。謝謝 –

+0

然後請接受答案關閉它。 –

回答

0

嘗試:

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:output method="text" encoding="UTF-8" /> 

<xsl:template match="/Assessment"> 
    <xsl:for-each select="Section"> 
     <xsl:value-of select="@ID"/> 
     <xsl:text>-</xsl:text> 
     <xsl:value-of select="."/> 
     <xsl:text>&#10;</xsl:text> 
    </xsl:for-each> 
</xsl:template> 

</xsl:stylesheet>