使用XSL链接的文本作为HTML弹出窗口

时间:2014-04-24 12:40:39

标签: html css xml arcgis

我正在使用自定义xsl模板为ESRI ArcMap制作HTML弹出窗口。对于我的xsl文件,代码运行良好,除了不显示弹出窗口中我的文档/图像的完整链接,我只想显示超链接"文本"或文件名(image.jpg或file.doc)。

链接到内部文档/图像的代码是:

<xsl:when test="FieldValue[starts-with(., '\\')]">
<a href="_blank"><xsl:attribute name="href"><xsl:value-of select="FieldValue"/>
</xsl:attribute><xsl:value-of select="FieldValue"/>
</a>
</xsl:when>

它适用于图像和pdf文件,但是,它确实为我提供了一个窗口来打开或保存word文档的文件,这不是一个真正的问题,但我更喜欢它可以直接在窗口中打开。目标是在弹出窗口的表中的不同行中有多个链接,并希望只有一个代码用于所有链接(包括图像,.doc和.pdf文件)。

整个代码是:

<?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheetversion="1.0"xmlns:xsl="http://www.w3.org/1999/XSL/Transform"xmlns:fo="http://www.w3.o       rg/1999/XSL/Format">
    <xsl:template match="/">
   <html>
   <head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
       <style type="text/css" media="screen">
             .align-left { float:left; margin: 0 15px 15px 0; }
             .align-right { float:right; margin: 0 0 15px 15px; }
       </style>
   </head>
  <body>
     <img src="C:\DATA\image.bmp" alt="Logo" class="align-left" />
     <img src="C:\DATA\image2.bmp" alt="Logo2" class="align-right" />
     <center style="font-family: helvetica; font-size: 17px; color: black"><strong>TEXT</strong></center>
    <xsl:variable name="nameCol" select="FieldsDoc/Fields/Field/FieldName"/>
    <body style="margin:0px 0px 0px 0px;overflow:auto;background:#ffffff;"></body>
    <iframe width="300" height="0"></iframe>
    <table style="font-family:Arial,Verdana,Times;font-size:14px;text-align:left;width:100%;border:1;padding:5px 5px 5px 5px">
    <tr bgcolor="#348017">        
    <xsl:if test="string-length($nameCol) != 0">
    <th width="50%" align="left">Field Name</th>
 </xsl:if>
   <th width="50%" align="left">Field Value</th>
 </tr>
  <xsl:variable name="index" select="1"/>
  <xsl:for-each select="FieldsDoc/Fields/Field">
 <tr>
    <xsl:if test="(position() +1) mod 2">
    <xsl:attribute name="bgcolor">#6CBB3C</xsl:attribute>
</xsl:if>
<xsl:if test="string-length($nameCol) != 0">
 <td>
   <xsl:value-of select="FieldName"/>
 </td>
</xsl:if>
 <td>
   <xsl:choose>
    <xsl:when test="FieldValue[starts-with(., 'www.')]">
    <a target="_blank"><xsl:attribute name="href">http://<xsl:value-of select="FieldValue"/>
    </xsl:attribute><xsl:value-of select="FieldValue"/>
   </a>
  </xsl:when>
  <xsl:when test="FieldValue[starts-with(., 'http:')]">
    <a target="_blank"><xsl:attribute name="href"><xsl:value-of select="FieldValue"/>
    </xsl:attribute><xsl:value-of select="FieldValue"/>
  </a>
</xsl:when>
 <xsl:when test="FieldValue[starts-with(., 'https:')]">
  <a target="_blank"><xsl:attribute name="href"><xsl:value-of select="FieldValue"/>
  </xsl:attribute><xsl:value-of select="FieldValue"/>
 </a>
</xsl:when>
<xsl:when test="FieldValue[starts-with(., '\\')]">
  <a href="_blank"><xsl:attribute name="href"><xsl:value-of select="FieldValue"/>
  </xsl:attribute><xsl:value-of select="FieldValue"/>
 </a>
</xsl:when>
<xsl:otherwise>
  <xsl:value-of select="FieldValue"/>
 </xsl:otherwise>
 </xsl:choose>
</td>
</tr>
</xsl:for-each>
</table>
<br/>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

我是HTML,CSS和XSL的新手,但是尝试学习以及任何帮助都表示赞赏。

由于

1 个答案:

答案 0 :(得分:0)

环顾四周,我找到了一个解决方案。

此代码也以我需要的方式工作,给我一个超链接的“链接”而不是整个路径。

<xsl:when test="FieldValue[starts-with(., '\\')]">
<a href="_blank">
<xsl:attribute name="href">
<xsl:value-of select="FieldValue"/>
</xsl:attribute>
<xsl:text>Link</xsl:text>
</a>
</xsl:when>

另一个问题;我的图像/文档在服务器上(//服务器/文件)但是我也有可能需要嵌入到同一个表中的视频(我已经完成并且它可以工作)我将如何制作代码以便它使用

<a href="_blank" ></a> 

标记文件/图像并使用

<embed src="_blank" ></embed>

视频标记。

是否改为:

<xsl:when test="FieldValue[starts-with(., '\\')]">

读取文件类型?

我也很感谢让我的代码更好的建议。

由于