我有几个XML文档,其中每个文档都是书中的一个章节。所有这些文件都合并到一个DOMDocument中,其中<book>
作为根元素添加。使用参数值作为位置
DOM文档获取的结构如下:(?即如default.php章= 1)
<book>
<chapter title="This is the first chapter">
<section title="This is the first section">
<paragraph title="This is the first paragraph">This is the paragraph content</paragraph>
</section>
</chapter>
<chapter title="This is the second chapter">
<section title="This is the first section">
<paragraph title="This is the first paragraph">This is the paragraph content</paragraph>
</section>
</chapter>
</book>
我成功地实现了表的内容,我可以用查询字符串链接选择章节。当我尝试打开一章时,参数“章节”被设置为查询字符串。
如何成功显示与查询字符串相等的章节?我从param设置位置出现问题。我收到一个“未定义的变量”错误。但是,当我在价值中使用它时没有错误。
<xsl:param name="chapter" />
<xsl:template match="//chapter[$chapter]">
<html>
<head>
<title><xsl:value-of select="$chapter"/> - <xsl:value-of select="@title"/></title>
</head>
<body>
<h1>
Chapter <xsl:value-of select="$chapter"/> <xsl:value-of select="@title"/>
</h1>
<xsl:apply-templates />
</body>
</html>
</xsl:template>
所以,我想的是,当用户访问他得到的唯一1章这样的“如default.php章= 1?”:
<html>
<head>
<title>Chapter 1 - This is chapter 1</title>
</head>
<body>
<h1>Chapter 1 - This is chapter 1</h1>
blablablablablablabla
</body>
</html>
你不能在使用变量的。我不明白你想达到什么目的。你有没有发布你期望的目标XML? –
Peter
我用我想要的结果更新了我的问题。我只想根据查询字符串显示1个章节。 – janlindso