以文本方式查看主题

-  计算机科学论坛  (http://bbs.xml.org.cn/index.asp)
--  『 XSL/XSLT/XSL-FO/CSS 』  (http://bbs.xml.org.cn/list.asp?boardid=8)
----  XSL问题,好心人帮忙调试一下!  (http://bbs.xml.org.cn/dispbbs.asp?boardid=8&rootid=&id=23993)


--  作者:make_love
--  发布时间:11/6/2005 7:31:00 PM

--  XSL问题,好心人帮忙调试一下!
<!--XML文档-->
<?xml version="1.0" encoding="GB2312"?>
<?xml-stylesheet type="text/xsl" href="xslsample2.xsl"?>
<唐诗>
 <五言绝句>
  <作者 字号="太白">李白</作者>
  <标题>静夜思</标题>
  <内容>床前明月光,疑是地上霜.
      举头望明月,低头思故乡.
      </内容>
 </五言绝句>
 <五言绝句>
  <作者 字号="太白">李白</作者>
  <标题>春晓</标题>
  <内容>春眠不觉晓,处处闻啼鸟.
      夜来风雨声,花落知多少.
      </内容>
 </五言绝句>
 <五言绝句>
  <作者 字号="季凌">王之涣</作者>
  <标题>登鹤雀楼</标题>
  <内容>白日依山尽,黄河入海流.
      欲穷千里目,更上一层楼.
</内容>
 </五言绝句>
 <五言绝句>
  <作者 字号="摩诘">王维</作者>
  <标题>相思</标题>
  <内容>红豆生南国,春来发几枝.
      劝君多采吉,此物最相思.
</内容>
 </五言绝句>
</唐诗>

<!--第一份XML-->
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/TR/WD-xsl" xmlns:fo="http://www.w3.org/1999/XSL/Format">
 <xsl:template match="/">
  <xsl:for-each select="/唐诗/五言绝句">
   <b>
    <xsl:value-of select="标题"/>
   </b>
   <xsl:value-of select="作者"/>
   <br/>
   <xsl:value-of select="内容"/>
   <hr/>
  </xsl:for-each>
 </xsl:template>
</xsl:stylesheet>

运行成功

<!--第二份-->
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/TR/WD-xsl" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template match="/">
<xsl:for-each select="唐诗/五言绝句">
<xsl:apply-templates />
</xsl:for-each>
</xsl:template>
<xsl:template match="唐诗/五言绝句" >
<xsl:if match="标题">
<b><xsl:value-of  /></b>
</xsl:if>
<xsl:if  match="内容">
<u><xsl:value-of  /></u>
</xsl:if>
<br/>
</xsl:template>
</xsl:stylesheet>

失败了,显示不出来,请帮忙看看

<!--第三份-->
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template match="/" >
<xsl:apply-templates select="唐诗/五言绝句/标题" />
</xsl:template>
<xsl:template match="唐诗/五言绝句/标题">
<xsl:choose>
 <xsl:when test=".[ value() = ' 静夜思' ]">
 你思念故乡吗?
 </xsl:when>
 <xsl:when test=".[ value() = ' 春晓 ']">
 春天来了,
 </xsl:when>
 <xsl:when test=".[value()='登鹤雀楼 ']">
 我们去旅游.
 </xsl:when>
 <xsl:otherwise>
 相思无益....
 </xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>

也失败了

<!--第四份-->
<?xml version="1.0" encoding="GB2312"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
 <xsl:template match="/">
  <xsl:apply-templates select="唐诗/五言绝句"/>
 </xsl:template>
 <xsl:template match="唐诗/五言绝句">
  <xsl:apply-templates select="标题"/>
  <br/>
  <xsl:apply-templates select="作者"/>
  <xsl:apply-templates select="作者/@字号"/>
  <br/>
  <xsl:apply-templates select="内容"/>
 </xsl:template>
  <xsl:template match="标题">
  <xsl:value-of />
 </xsl:template>
 <xsl:template match="作者">
作者:<xsl:value-of />
 </xsl:template>
 <xsl:template match="作者/@字号">
字:<xsl:value-of />
 </xsl:template>
 <xsl:template match="内容">
  <xsl:value-of />
  <hr/>
 </xsl:template>
</xsl:stylesheet>

还是失败,3份失败有点郁闷了,请帮忙调试调试!


--  作者:Qr
--  发布时间:11/7/2005 9:38:00 AM

--  
1、编码不一致,容易出问题。
2、
<?xml version="1.0" encoding="GB2312"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/TR/WD-xsl" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template match="/">
<xsl:apply-templates select="唐诗/五言绝句/*"/>
</xsl:template>
<xsl:template match="*" >
<xsl:if match="标题">
<b><xsl:value-of  /></b>
</xsl:if>
<xsl:if match="内容">
<u><xsl:value-of  /></u>
</xsl:if>
<br/>
</xsl:template>
</xsl:stylesheet>
3、
<?xml version="1.0" encoding="gb2312"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template match="/" >
<xsl:apply-templates select="唐诗/五言绝句/标题" />
</xsl:template>
<xsl:template match="唐诗/五言绝句/标题">
<xsl:choose>
<xsl:when test="text() = '静夜思'">
你思念故乡吗?
</xsl:when>
<xsl:when test="text() = '春晓'">
春天来了,
</xsl:when>
<xsl:when test="text() = '登鹤雀楼'">
我们去旅游.
</xsl:when>
<xsl:otherwise>
相思无益....
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
4、
<?xml version="1.0" encoding="GB2312"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template match="/">
  <xsl:apply-templates select="唐诗/五言绝句"/>
</xsl:template>
<xsl:template match="五言绝句">
  <xsl:apply-templates select="标题"/>
  <br/>
  <xsl:apply-templates select="作者"/>
  <xsl:apply-templates select="作者/@字号"/>
  <br/>
  <xsl:apply-templates select="内容"/>
</xsl:template>
  <xsl:template match="标题">
  <xsl:value-of select="."/>
</xsl:template>
<xsl:template match="作者">
作者:<xsl:value-of select="."/>
</xsl:template>
<xsl:template match="作者/@字号">
字:<xsl:value-of select="."/>
</xsl:template>
<xsl:template match="内容">
  <xsl:value-of select="."/>
  <hr/>
</xsl:template>
</xsl:stylesheet>
W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
46.875ms