0

我在 xml 文件中有以下标签:

<more_details>
    <source>192.168.1.1</source>
    <destination>10.10.10.10</destination>
    <vlan>192.168.0.0/24</vlan>
    <date>29/3/1391</date>
    <count>24</count>
</more_details>

我想使用xsl在tooltip中设计一个表格;(我希望当鼠标移过页面中的特定链接时,它代表表格中的数据。数据来自xml文件)

我在我的 xsl 文件中编写以下行来实现这个目标:

<a href="">
    <xsl:attribute name="title"><table style='color:#efefef; background:none !important;'>
    <tr>
        <td><xsl:value-of select="source"/></xsl:value-of><td>
        <td><xsl:value-of select="destination"/></xsl:value-of></td>
        <td><xsl:value-of select="vlan"/></xsl:value-of></td>
        <td><xsl:value-of select="date"/></xsl:value-of></td>
        <td><xsl:value-of select="count"/></xsl:value-of></td>
    </tr>
    </table></xsl:attribute>
    more details
</a>

它适用于 html 文件,但不适用于 xsl 文件;XSL 会自动删除所有 html 标记。

像这样:

<a href="" title="192.168.2.1125.45.24.5192.168.0.0/2429/2/1390 - 12:1424">
  link
</a>

意思是当鼠标经过“more details”字样时,tooltip中显示的结果是:

192.168.2.1125.45.24.5192.168.0.0/2429/2/1390 - 12:1424

我想在表格的一列中显示上述每个标签。(要结构化)但是当我运行程序时,它显示的数据不是结构化格式(不在表格中)

我还研究了第二种方式:

<a href="">
  <xsl:attribute name="title">&lt;table style='color:#efefef; background:none !important;'>
    <tr>
      <td><xsl:value-of select="source"/>&lt;/td>
      <td><xsl:value-of select="destination"/>&lt;/td>
      <td><xsl:value-of select="vlan"/>&lt;/td>
      <td><xsl:value-of select="date"/>&lt;/td>
      <td><xsl:value-of select="count"/>&lt;/td>
    </tr>
  </table></xsl:attribute>
    more details
</a>

它也不起作用。第二种方式的结果是:

我真的需要你的帮助,任何答案都将不胜感激。非常感谢

4

1 回答 1

1

titleHTML属性中不能有表格。这是不可能的,停止尝试。

你可以做什么:

  1. 使用可用的 JavaScript 库之一来生成自定义工具提示。例如,jQuery 有用于此的插件,但还有很多其他的。这些库可以在鼠标悬停时显示任何类型的 HTML,因此表格不会成为问题。
  2. 只需将换行符添加到您的属性。大多数浏览器都支持属性中的换行符title并将它们显示在屏幕上。不像桌子那么漂亮,但可能就足够了。

我只会详细介绍第二个选项。第一个超出了这个问题的范围。

<a href="">
  <xsl:attribute name="title">
     <xsl:value-of select="concat('Source: ', source, '&#10;')" />
     <xsl:value-of select="concat('Destination: ', destination, '&#10;')" />
     <xsl:value-of select="concat('VLAN: ', source, '&#10;')" />
     <xsl:value-of select="concat('Date: ', date, '&#10;')" />
     <xsl:value-of select="concat('Count: ', count)" />
  </xsl:attribute>
  <xsl:text>more details</xsl:text>
</a>
于 2012-08-14T11:59:24.280 回答