使用XSL的select 有選擇的顯示數據

1.XML文檔

<?xml version="1.0" encoding="GB2312"?>
<?xml-stylesheet type="text/xsl" href="book2.xsl"?>
<BookLib>
 <Book>
  <Title>Windows程序設計</Title>
  <Author>
   <name>好孩子</name>
   <Email>[email protected]</Email>
  </Author>
  <Press>
  <PressDate>2000年5月1日</PressDate>
  <PressCompany>南京出版社</PressCompany>
  </Press>
  <Price>49.00元</Price>
 </Book>
 <Book>
  <Title>深入潛出XML</Title>
  <Author>
   <name>老虎工作室</name>
   <Email>[email protected]</Email>
  </Author>
  <Press>
  <PressDate>2006年5月12日</PressDate>
  <PressCompany>北京出版社</PressCompany>
  </Press>
  <Price>28.00元</Price>
 </Book>
 <Book>
  <Title>人工智能技術導論</Title>
  <Author>
   <name>廉師友</name>
   <Email>[email protected]</Email>
  </Author>
  <Press>
  <PressDate>2006年7月12日</PressDate>
  <PressCompany>上海出版社</PressCompany>
  </Press>
  <Price>18.00元</Price>
 </Book>
</BookLib>

上面的XML文檔定義了根元素爲BookLib,三個子元素爲Book的樹,

其中Book元素又有Title,Author,Press,Price 四個元素,其中Author元素又有name和Email兩個子元素,

Press元素又有PressDate和PressCompany元素,

2.XSL文檔的內容

<?xml version="1.0" encoding="GB2312"?>
<xsl:stylesheet xmlns:xsl="
http://www.w3.org/TR/WD-xsl">
 <xsl:template match="/">
  <html>
   <xsl:apply-templates/>
  </html>
 </xsl:template>
 <xsl:template match="BookLib">
  <body>
   <xsl:apply-templates/>
  </body>
 </xsl:template>
 <xsl:template match="Book">
  <xsl:apply-templates />
 </xsl:template>
 <xsl:template match="Title">
  <Font size="3" color="#0000FF">
   <BR/>
   <xsl:value-of select="."/>
  </Font>
 </xsl:template>
 <xsl:template match="Author">
  <Font size="3" color="#FF0000">
   <BR/>
   <xsl:value-of select="name"/>
  </Font>
 </xsl:template>
 <xsl:template match="Press">
  <Font size="3" color="#FF00FF">
   <BR/>
   <xsl:value-of select="."/>
  </Font>
 </xsl:template>
 <xsl:template match="Price">
  <Font size="3" color="#999999">
   <BR/>
   <xsl:value-of select="."/>
  </Font>
 </xsl:template>
</xsl:stylesheet>

其中


xsl:value-of select="name" 這行表示我們顯示的是Author元素的name子元素,

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章