2012-02-03 54 views
1

我正在處理XML中的一個簡單字典,現在我正在嘗試輸出一些垂直字,但是它們全都出現在沒有空格的行上。垂直輸出XSL和XML

這是一些XML文件的

<thesaurus> 
    <dictionary> 
    <language>English</language> 
    <word type="1">word 1</word> 
    <word type="2">word 2</word> 
    <word type="3">word 3</word> 
    <word type="4">word 4</word> 
    <word type="5">word 5</word> 
    <word type="6">word 6</word> 
    </dictionary> 
</thesaurus> 

這是我的第一個 「差不多」 的解決方案

<xsl:template match="/"> 
    <html> 
     <body> 

      <xsl:apply-templates select="//word"> 

      <xsl:sort order="ascending"/> 
     </xsl:apply-templates> 
     </body> 
    </html> 
    </xsl:template> 
</xsl:stylesheet> 

這種解決方案只能打印出所有的字像這樣

AgentsColorFoundationsGrainPartialPogotypePretendSilentStrollTender

我的第二次嘗試是這樣

<xsl:for-each select="thesaurus"> 
     <h1> <xsl:value-of select="//word"/></h1> 
       </xsl:for-each> 

這樣一來,我可以樣式的話,他們會打印垂直,但事情是隻有第一個的話被打印。 =/

將是偉大的一個提示:)

感謝

回答

1

使用該模板:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:output method="xml" indent="yes"/> 

    <xsl:template match="/"> 
    <html> 
     <body> 
     <xsl:apply-templates select="*/*/word"> 
      <xsl:sort order="ascending"/> 
     </xsl:apply-templates> 
     </body> 
    </html> 
    </xsl:template> 

    <xsl:template match="word"> 
    <xsl:value-of select="."/> 
    <br/> 
    </xsl:template> 

</xsl:stylesheet> 

輸出:

<html> 
    <body>word 1<br />word 2<br />word 3<br />word 4<br />word 5<br />word 6<br /></body> 
</html> 
+0

它的工作就像一個魅力的..當然非常感謝:) – Dymond 2012-02-03 20:31:23

+0

@FelipeOtarola,不客氣! – 2012-02-04 08:13:15