xsl的问题

kelvinfly 2003-10-16 07:26:25
我试图用以下的xsl 解析 xml文档, 获得所有title的值。但和预期不符,为什么?环境是xmlspy2004。并且xpath://title 的估值也对的

<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
>
<xsl:template match="//title">
<xsl:value-of select="."/>
</xsl:template>

</xsl:stylesheet>

/////////////////////////////////////////////////////////////////////
<?xml version="1.0"?>
<books>
<book category="reference">
<author>Nigel Rees</author>
<title>Sayings of the Century</title>
<price>8.95</price>
</book>
<book category="fiction">
<author>Evelyn Waugh</author>
<title>Sword of Honour</title>
<price>12.99</price>
</book>
<book category="fiction">
<author>Herman Melville</author>
<title>Moby Dick</title>
<price>8.99</price>
</book>
<book category="fiction">
<author>J. R. R. Tolkien</author>
<title>The Lord of the Rings</title>
<price>22.99</price>
</book>
</books>
...全文
28 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
dory 2003-10-17
  • 打赏
  • 举报
回复
this is ok``````

the xsl:

-------------------------------

<?xml version="1.0" encoding="gb2312"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:template match="/">
<xsl:for-each select="books/book/title">

<xsl:value-of select="./text()"/><xsl:apply-templates/>

</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
dory 2003-10-17
  • 打赏
  • 举报
回复
this is ok
----------------------------------------------------------
<?xml version="1.0" encoding="GB2312"?>
<?xml-stylesheet type="text/xsl" href="hello.xsl"?>
<books>
<book category="reference">
<author>Nigel Rees</author>
<title>Sayings of the Century</title>
<price>8.95</price>
</book>
<book category="fiction">
<author>Evelyn Waugh</author>
<title>Sword of Honour</title>
<price>12.99</price>
</book>
<book category="fiction">
<author>Herman Melville</author>
<title>Moby Dick</title>
<price>8.99</price>
</book>
<book category="fiction">
<author>J. R. R. Tolkien</author>
<title>The Lord of the Rings</title>
<price>22.99</price>
</book>
</books>

-------------------------------------------------
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
>
<xsl:template match="//title">
<xsl:value-of select="text()"/>
</xsl:template>

</xsl:stylesheet>
ssm1226 2003-10-17
  • 打赏
  • 举报
回复
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
>
<xsl:template match="node()">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="//title">
<xsl:value-of select="."/><br/>
</xsl:template>

</xsl:stylesheet>
kingdomzhf 2003-10-17
  • 打赏
  • 举报
回复
把title换成title1或其他
cybernaute 2003-10-17
  • 打赏
  • 举报
回复
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="//book">
<xsl:for-each select="title">
<xsl:value-of select="."/><br/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

原作者的错误在
select="."显示的是与title同一级的所有结点的值
davinic1209 2003-10-16
  • 打赏
  • 举报
回复
提问的代码错在哪里?
wolf004 2003-10-16
  • 打赏
  • 举报
回复
或是
<xsl:template match="/">
<xsl:for-each select="books/book" >
<xsl:value-of select="title"/>
</xsl:for-each>

</xsl:template>
wolf004 2003-10-16
  • 打赏
  • 举报
回复
<xsl:template match="/">
<xsl:for-each select="books/book/title" >
<xsl:value-of select="."/>
</xsl:for-each>

</xsl:template>
nolonely 2003-10-16
  • 打赏
  • 举报
回复
try:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="//book">
<xsl:for-each select="title">
<xsl:value-of select="."/><br/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

8,906

社区成员

发帖
与我相关
我的任务
社区描述
XML/XSL相关问题讨论专区
社区管理员
  • XML/XSL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧