簡體   English   中英

垂直輸出XSL和XML

[英]Vertical output XSL and XML

我正在使用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>

該解決方案只打印出所有這樣的單詞

特工ColorFoundationsGrainPartialPogotype假裝無聲漫步招標

我的第二次嘗試是這樣的

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

這樣,我就可以對單詞進行樣式設置,並且它們將垂直打印,但事實是,只有第一個單詞可以打印。 = /

一個提示會很棒:)

謝謝

使用此模板:

<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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM