gpt4 book ai didi

xml - 链接、xsl 以及为什么 chrome 连接换行符(又名 %0A HEX 符号)

转载 作者:行者123 更新时间:2023-12-04 06:10:51 25 4
gpt4 key购买 nike

我在使用 XSL 在 Chrome 中显示链接时遇到了一个有趣的问题:每个链接都与十六进制符号“%0A”连接。
因此,如果链接是“www.google.com”,它将显示为“www.google.com%0A”。
此问题仅发生在 google chrome 中 - Internet Explorer 和 FireFox 正确显示链接。
所以我的问题是:如何防止谷歌浏览器弄乱链接?
这是 XML 文件的示例:

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="builtMathCSStatisticsXML.xsl"?>
<channel>
<item>
<title>algrbra
</title>
<type>class notes
</type>
<staff>Noga Alon
</staff>
<semester>
</semester>
<year>2011
</year>
<donor>anonymous
</donor>
<link>https://skydrive.live.com/self.aspx?path=%2f%d7%9e%d7%aa%d7%9e%d7%98%d7%99%d7%a7%d7%94%2f%d7%90%d7%9c%d7%92%d7%91%d7%a8%d7%94%20%d7%911.%d7%a9%d7%99%d7%a2%d7%95%d7%a8%d7%99%d7%9d%20%d7%95%d7%aa%d7%a8%d7%92%d7%99%d7%9c%d7%99%d7%9d.%d7%a0%d7%95%d7%92%d7%94%20%d7%90%d7%9c%d7%95%d7%9f%5e.%d7%aa%d7%a9%d7%a1%5e4%5e4%d7%96%20-%20%d7%a8%d7%95%d7%a2%d7%99%20%d7%a7%d7%9c%d7%99%d7%99%d7%9f.pdf&amp;cid=1f8a5680599afff9
</link>
</item>
...
</channel>

这是 xsl 文件:
<?xml version="1.0"?
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
<script src="sorttable.js"></script>
</head>
<body dir="rtl">
<h2>Math CS and Statistics</h2>
<table class="sortable">
<thead>
<tr bgcolor="#9acd32">
<th>course</th>
<th>type</th>
<th>proffesor</th>
<th>semster</th>
<th>year</th>
<th>donors</th>
<th>links</th>
</tr>
</thead>
<tbody>
<xsl:for-each select="channel/item">
<xsl:sort select="title" />
<tr onMouseOver="this.bgColor='yellow';" onMouseOut="this.bgColor='white';">
<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="type"/></td>
<td><xsl:value-of select="staff"/></td>
<td><xsl:value-of select="semester"/></td>
<td><xsl:value-of select="year"/></td>
<td><xsl:value-of select="donor"/></td>
<td>
<a target="_blank"><xsl:attribute name="href">
<xsl:value-of select="link"/>
</xsl:attribute>link</a>
</td>
</tr>
</xsl:for-each>
</tbody>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

谢谢!

最佳答案

此行为符合 XSLT 1.0 Spec ,而且解释相当棘手:

NOTE:When an xsl:attribute contains a text node with a newline, then the XML output must contain a character reference. For example,

<xsl:attribute name="a">x
y</xsl:attribute>

will result in the output

a="x&#xA;y"

(or with any equivalent character reference). The XML output cannot be

a="x
y"

This is because XML 1.0 requires newline characters in attribute values to be normalized into spaces but requires character references to newline characters not to be normalized. The attribute values in the data model represent the attribute value after normalization. If a newline occurring in an attribute value in the tree were output as a newline character rather than as character reference, then the attribute value in the tree created by reparsing the XML would contain a space not a newline, which would mean that the tree had not been output correctly.



所以,如果你真的不想要字符实体,写 :
<link>string</link>

而不是 :
<link>string
</link>

或者,使用 :
<xsl:attribute name="href">
<xsl:value-of select="normalize-space(link)"/>
</xsl:attribute>

但是,请注意,这将仅用一个空格替换任何一组非前导或非尾随空白字符。

关于xml - 链接、xsl 以及为什么 chrome 连接换行符(又名 %0A HEX 符号),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7797796/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com