难以使超链接在XML文档中工作 [英] Having difficulty making hyperlinks work in XML doc

查看:73
本文介绍了难以使超链接在XML文档中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对xml和xsl很新,所以这可能非常简单。我有一个包含一些数据的xml文件和一个xsl文件,可以将其处理成一个网页。什么不起作用的是超链接。我已经阅读了关于xlink如何工作的无穷无尽的页面,但对我来说它不是。没有错误,只是纯文本,没有超链接。我正在运行Firefox 2.0.0.3,但也尝试在IE7中获得完全相同的结果。

这是一些样本xml,从w3schools取消并略微按摩。我希望有人可以指出我哪里出错。


谢谢

Rob


[html ]<?xml version =" 1.0" encoding =" ISO-8859-1"?>

<?xml-stylesheet type =" text / xsl" href =" bookstore.xsl"?>


< bookstore xmlns:xlink =" http://www.w3.org/1999/xlink">


< book>

< description xlink:type =" simple" xlink:href =" ../ RPS / ComingUp.xml">

Text1

< / description>

< /预订>


< book>

< description

xlink:type =" simple"

xlink:href =" http://www.cam.ac.uk"

xlink:show =" new"> Text2< / description>

< / book>


< / bookstore> [/ html]


和一些相应的xsl


[html]<?xml version =" 1.0" encoding =" ISO-8859-1"?>


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


< xsl:template match =" /">

< html>


< head>

< meta http-equiv =" Content-Language" content =" en-gb">< / meta>

< meta http-equiv =" Content-Type"含量=" text / html的; charset = windows-1252">< / meta>

< title>书店< / title>

< link rel =" stylesheet"类型= QUOT;文本/ CSS" href =" ../ rps.css">< / link>


< / head>


< body> ;

< xsl:for-each select =" bookstore / book">

< xsl:value-of select =" description" /> < br />

< / xsl:for-each>

< / body>

< / html>

< / xsl:template>


< / xsl:stylesheet> [/ html]

渐弱: 请使用html或代码标签作为源代码。谢谢,主持人。

解决方案

欢迎来到TheScripts TSDN ...


试试这段代码:

[html]<?xml version =" 1.0" encoding =" ISO-8859-1"?>


< xsl:stylesheet version =" 1.0"

xmlns:xsl =" http://www.w3.org/1999/XSL/Transform"

xmlns:xlink =" http://www.w3.org/1999/xlink"

exclude-result-prefixes =" xlink" >


< xsl:template match =" /">

< html>


< head>

< meta http-equiv =" Content-Language" content =" en-gb">< / meta>

< meta http-equiv =" Content-Type"含量=" text / html的; charset = windows-1252">< / meta>

< title>书店< / title>

< link rel =" stylesheet"类型= QUOT;文本/ CSS" href =" ../ rps.css">< / link>


< / head>


< body>

< xsl:for-each select =" bookstore / book">

< xsl:if test =" description [@ xlink:type =''simple''和@xlink:href]">

< a href =" {description / @ xlink:href}">< xsl: value-of select =" description"< / a>< br />

< / xsl:if>


< / xsl:for-each>

< / body>

< / html>

< / xsl:template>


< / xsl:stylesheet> [/ html]


有关详细信息,请参阅使用XSLT构建XLink应用程序


< blockquote>感谢您的建议。可悲的是,当我运行你的代码时,我只得到一个空白页面。当我删除if测试时,页面显示超链接,这是明确的进展。不幸的是,链接只是指向xml文件,而不是指向我在xlink:href属性中指定的URL,即file:/// E:/www/TryOut/book2.xml"而不是,例如,http://www.cam.ac.uk"。

谢谢

Rob


我在IE7和FireFox 2.0上测试过。

点击Text2链接打开http://www.cam.ac.uk/网站。


您使用的浏览器是什么?


I''m quite new to xml and xsl, so this could be quite simple. I have an xml file with some data in it and an xsl file to process it into a web page. What doesn''t work is hyperlinks. I''ve read endless pages about how xlink works, but for me it just doesn''t. No errors, just plain text and no hyperlinks. I''m running Firefox 2.0.0.3 but have also tried in IE7, getting exactly the same result.
Here is some sample xml, lifted from w3schools and slightly massaged. I hope someone can point out where I''m going wrong.

Thanks
Rob

[html]<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="bookstore.xsl"?>

<bookstore xmlns:xlink="http://www.w3.org/1999/xlink">

<book>
<description xlink:type="simple" xlink:href="../RPS/ComingUp.xml">
Text1
</description>
</book>

<book>
<description
xlink:type="simple"
xlink:href="http://www.cam.ac.uk"
xlink:show="new">Text2</description>
</book>

</bookstore>[/html]

and some corresponding xsl

[html]<?xml version="1.0" encoding="ISO-8859-1"?>

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

<xsl:template match="/">
<html>

<head>
<meta http-equiv="Content-Language" content="en-gb"></meta>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252"></meta>
<title>Bookstore</title>
<link rel="stylesheet" type="text/css" href="../rps.css"></link>

</head>

<body>
<xsl:for-each select="bookstore/book">
<xsl:value-of select="description"/><br/>
</xsl:for-each>
</body>
</html>
</xsl:template>

</xsl:stylesheet>[/html]

Waning: Please use html or code tags for source code. Thanks, moderator.

解决方案

Welcome to TheScripts TSDN...

Try this code:
[html]<?xml version="1.0" encoding="ISO-8859-1"?>

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xlink="http://www.w3.org/1999/xlink"
exclude-result-prefixes="xlink" >

<xsl:template match="/">
<html>

<head>
<meta http-equiv="Content-Language" content="en-gb"></meta>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252"></meta>
<title>Bookstore</title>
<link rel="stylesheet" type="text/css" href="../rps.css"></link>


</head>

<body>
<xsl:for-each select="bookstore/book">
<xsl:if test="description[@xlink:type = ''simple'' and @xlink:href]">
<a href="{description/@xlink:href}"><xsl:value-of select="description"/></a><br />
</xsl:if>

</xsl:for-each>
</body>
</html>
</xsl:template>

</xsl:stylesheet>[/html]

For more details see Building XLink Applications with XSLT.


Thank you for your advice. Sadly, when I run your code, I just get a blank page. When I removed the if test, the page showed with hyperlinks, which is definite progress. Unfortunately the links just point back to the xml file, not to the URL I specified in the xlink:href attribute, viz "file:///E:/www/TryOut/book2.xml" instead of, for example, "http://www.cam.ac.uk".
Thanks
Rob


I tested on IE7 and FireFox 2.0.
Clicking on Text2 link has open http://www.cam.ac.uk/ site.

What browser are you using?


这篇关于难以使超链接在XML文档中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆