0
这是我所追求的。在标准的HTML我可以做一个链接列表如下:XML和XSLT创建链接菜单<a href="URL ">Text Description</a>不同的网址和文字
<p>
<a href="/name-of-volume/name-of-book/00-Preamble/Preamble.xml">Preamble</a>
<a href="/name-of-volume/name-of-book/01-Chapter-01/chapter_1.xml">Chapter 1</a>
<a href="/name-of-volume/name-of-book/02-Chapter-02/chapter_2.xml">Chapter 2</a>
<a href="/name-of-volume/name-of-book/03-Chapter-03/chapter_3.xml">Chapter 3</a>
<a href="/name-of-volume/name-of-book/04-Chapter-04/chapter_4.xml">Chpater 4</a>
<a href="/name-of-volume/name-of-book/05-Chapter-05/chapter_5.xml">Chapter 5</a>
<a href="/name-of-volume/name-of-book/06-Chapter-06/chapter_6.xml">Chapter 6</a>
<a href="/name-of-volume/name-of-book/07-Chapter-07/chapter_7.xml">Chapter 7</a>
<a href="/name-of-volume/name-of-book/08-Chapter-08/chapter_8.xml">Chapter 8</a>
<a href="/name-of-volume/name-of-book/09-Chapter-09/chapter_9.xml">Chapter 9</a>
<a href="/name-of-volume/name-of-book/10-Chapter-10/chapter_10.xml">Chapter 10</a>
<a href="/name-of-volume/name-of-book/11-Appendix/Appendix.xml">Appendix</a>
</p>
浏览器显示这个时候,之间的文本的开始和结束标记是在屏幕的链接上显示的内容,我们没有看到实际的网址。当我们点击链接文字时,我们跳转到网址。
使用下面的XML示例(意识到可能有更好的设置),我该如何设置它(包括XSLT),以便在浏览器屏幕上获得相同的效果。也就是说,我想查看链接文字,但不想显示实际的网址。
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="/style-sheets/master-rulebook.xsl"?>
<ROOT>
<side_menu_div>
<link-text>Preamble</link-text>
<chapter-link>/name-of-volume/name-of-book/00-Preamble/Preamble.xml</chapter-link>
<link-text>Chapter 1</link-text>
<chapter-link>/name-of-volume/name-of-book/01-Chapter-01/chapter_1.xml"</chapter-link>
<link-text>Chapter 2</link-text>
<chapter-link>/name-of-volume/name-of-book/02-Chapter-02/chapter_2.xml"></chapter-link>
<link-text>Chapter 3</link-text>
<chapter-link>/name-of-volume/name-of-book/03-Chapter-03/chapter_3.xml"></chapter-link>
<link-text>Chapter 4</link-text>
<chapter-link>/name-of-volume/name-of-book/04-Chapter-04/chapter_4.xml"</chapter-link>
<link-text>Chapter 5</link-text>
<chapter-link>/name-of-volume/name-of-book/05-Chapter-05/chapter_5.xml"</chapter-link>
<link-text>Chapter 6</link-text>
<chapter-link>/name-of-volume/name-of-book/06-Chapter-06/chapter_6.xml"</chapter-link>
<link-text>Chapter 7</link-text>
<chapter-link>/name-of-volume/name-of-book/07-Chapter-07/chapter_7.xml"</chapter-link>
<link-text>Chapter 8</link-text>
<chapter-link>/name-of-volume/name-of-book/08-Chapter-08/chapter_8.xml"</chapter-link>
<link-text>Chapter 9</link-text>
<chapter-link>/name-of-volume/name-of-book/09-Chapter-09/chapter_9.xml"</chapter-link>
<link-text></link-text>
<chapter-link>/name-of-volume/name-of-book/10-Chapter-10/chapter_10.xml"Chapter 10</chapter-link>
<link-text></link-text>
<chapter-link>/name-of-volume/name-of-book/11-Appendix/Appendix.xml"Appendix</chapter-link>
</side_menu_div>
</ROOT>
我相信上面的XML可以正常工作,但是我不知道如何设置XSLT。
使用从下面的海报协助下,我的XSLT现在看起来是这样,它很好地工作
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:output method="html" encoding="utf-8" />
<xsl:strip-space elements="*" />
<xsl:template match="/">
<html>
<body style="background-color:#fffc99; font-size:16pt;">
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="ROOT">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="side_menu_div">
<div style="width: 10%; height: 100%; position: fixed; padding-right: 1em; background: #578be0; " >
<xsl:for-each select="/ROOT/side_menu_div/link-text">
<xsl:variable name="index" select="position()" />
<a href="{/ROOT/side_menu_div/chapter-link[$index]}">
<xsl:value-of select="." />
</a>
<br/>
</xsl:for-each>
</div>
</xsl:template>
<xsl:template match="chapter">
<div style="width: 90%; height: auto; position: absolute; margin-left: 10%; padding-left: 1em; background: #fffc99; " >
<xsl:apply-templates/>
</div>
</xsl:template>
这几乎工作有所帮助。我得到的菜单和链接工作,但.........链接文本重叠(向下)到下一个链接,每个链接文本实际上打开它下面的链接。例如,第1章的链接实际上是打开第2章,第2章的链接打开第3章等等。我将尝试发布一个屏幕截图,以便输出清楚。 –
这确实有效。我必须清理我的XML(如上所述)。我仍然在真实章节的实际代码中存在一些垃圾,并且必须编辑我的XSLT以添加
标记以及一些填充和边距。现在看起来不错并且有效。 –