我正在使用自定义 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 的新手,但我正在努力学习,因此非常感谢您的帮助。
谢谢
最佳答案
环顾四周,我找到了解决方案。
这段代码也按照我需要的方式工作,给我一个超链接“链接”而不是整个路径。
<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>
另一个问题;我的图像/文档在服务器 (//server/file) 上,但是我也有可能需要嵌入同一个表中的视频(我已经完成了并且它有效)我将如何制作代码以便它使用
<a href="_blank" ></a>
标记文档/图像并使用
<embed src="_blank" ></embed>
视频标签。
是否改变了:
<xsl:when test="FieldValue[starts-with(., '\\')]">
读取文件类型?
我也很感激能改进我的代码的建议。
谢谢
关于html - 将文本用于链接,将 XSL 用于 HTML 弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23269180/