是否有可能获得由xsl填充的项的值

Is it possible to get the value of an item populated by xsl?

本文关键字:填充 xsl 有可能 是否      更新时间:2023-09-26

我正在使用一个具有XML文件的Flash地图。我使用XSLT从XML在地图的网页(在flash地图之外)上填充了一个列表。我想通过XSL向其中添加一个JS函数,该函数从XML中选择将与映射交互的(已填充的)元素。

例如,我的列表是50个州。以下是XML中的一小部分:

<attributes>
        <col name="State">Kentucky</col>
        <STATENAME>Kentucky</STATENAME>
  </attributes>

等等……所有50个州都包含在上面的XML中

下面是我如何填充列表的:

<table border="0">
      <tr bgcolor="#9acd32">
        <th>State</th>
      </tr>
<xsl:for-each select="map/layer/feature/attributes">
<xsl:sort select="STATENAME"/>
      <tr>
        <td><a onMouseOver='highlight()' onMouseOut='highlight_clear()'><xsl:attribute name="href">http://mysite.com/<xsl:value-of select="STATENAME"/>.html</xsl:attribute><xsl:value-of select="STATENAME" /></a></td>
      </tr>
      </xsl:for-each>
    </table>

所有50个州都以这种方式出现,并链接到他们各自的页面:http://mysite.com/statename.html

下面是Javascript代码:

function highlight() {
            theMap.features('State="Kentucky"').highlight({visible: true, fillColor: "#FFFF00", fillAlpha: 1.0});          
        }

这里的关键是('State="Kentucky"')我试图让State=在列表中填充的相同状态,而不必编写50个不同的函数-每个州一个。例如,当所有50个州都有人口时,如果鼠标移到德克萨斯州,它将自动显示theMap.features('State="Texas"');如果鼠标移到内布拉斯加州,它将显示内布拉斯加州。

I tried doing this:

function highlight() {
var sn='<xsl:value-of select="STATENAME"/>';
                theMap.features('State="sn"').highlight({visible: true, fillColor: "#FFFF00", fillAlpha: 1.0}); }

但它不起作用,我也不认为它会。但是,它本质上是我想要发生什么的想法。

想法?

您应该能够这样做:

<table border="0">
  <tr bgcolor="#9acd32">
     <th>State</th>
  </tr>
  <xsl:for-each select="map/layer/feature/attributes/STATENAME">
    <xsl:sort select="."/>
      <tr>
        <td>
          <a onMouseOver='highlight("{.}")' 
             onMouseOut='highlight_clear()'
             href='http://mysite.com/{.}.html'>
             <xsl:value-of select="." />
          </a>
        </td>
      </tr>
   </xsl:for-each>
</table>

然后将highlight()函数更改为:

function highlight(state) {
    theMap.features('State="' + state + '"')
          .highlight({visible: true, 
                      fillColor: "#FFFF00", 
                      fillAlpha: 1.0});          
}