Link to home
Start Free TrialLog in
Avatar of wellesleydpw
wellesleydpw

asked on

XSL HTML GIS PopUp - Referring to field value

Disclaimer - I'm completely unfamiliar with HTML.  I have an existing XSL template that lists all the fields and their values and I want to only select a specific field (rather than all of the fields) and refer to it multiple times so that I can provide hyperlinks to documents that have that field's value in it's file path like the following:
<xsl:attribute name="href">Q:\A_DPW\Images\WaterTieCards\<xsl:value-of select="FieldValue"/>.pdf

Open in new window

...and then
<xsl:attribute name="href">Q:\A_DPW\Images\SewerTieCards\<xsl:value-of select="FieldValue"/>.pdf

Open in new window


Here's the entire XSL template:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
      <xsl:template match="/">
            <html>
				<head>
					<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
				</head>
                  <body>
                        <xsl:variable name="nameCol" select="FieldsDoc/Fields/Field/FieldName"/>
                              <table border="1" width="300" cellpadding="5" cellspacing="0">
                                    <tr bgcolor="#9cbce2">
                                          <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">#D4e4f3</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="FieldName[starts-with(., 'Address')]">
                                                                  <xsl:variable name="WaterTieCard" select="FieldValue"/>
                                                                  <a target="_blank"><xsl:attribute name="href">Q:\A_DPW\Images\WaterTieCards\<xsl:value-of select="FieldValue"/>.pdf
                                                                  </xsl:attribute><xsl:value-of select="FieldValue"/>
                                                                  </a>
                                                            </xsl:when>
                                                            <xsl:when test="FieldName[starts-with(., 'VIDEO')]">
                                                                  <xsl:variable name="videoURL" select="FieldValue"/>
                                                                  <object width="425" height="355">
                                                                        <param name="movie" value="{$videoURL}"></param>
                                                                        <param name="wmode" value="transparent"></param>
                                                                        <embed src="{$videoURL}" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355">
                                                                        </embed>
                                                                  </object>
                                                            </xsl:when>
                                                            <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 target="_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>
                  </body>
            </html>
      </xsl:template>
</xsl:stylesheet>

Open in new window


Any help is appreciated.
Jeff
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

What kind of help do you need?  Are you getting errors?  Do you need to change the XSL?
Avatar of wellesleydpw
wellesleydpw

ASKER

Thanks Bob,
I would like to change the XSL.  Because I'm unfamiliar with the structure of the database, I'm not positive about how to code what I'm looking for.  Essentially, I would like use the values in a field called "Address" to create hyperlinks to multiple files and list those hyperlinks in a table.

Jeff
I don't see the input XML, but I can see:

1) Selecting a field name with an XPath expression:

<xsl:variable name="nameCol" select="FieldsDoc/Fields/Field/FieldName"/>

2) I will assume that FieldValue is FieldsDoc/Fields/Field/FieldName/FieldValue

3) A test expression when FieldName starts with 'Address', to build a file location from FieldValue:

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

        Q:\A_DPW\Images\WaterTieCards\<xsl:value-of select="FieldValue"/>.pdf
Thanks Bob,
Is there a way of selecting the field without the when test.  Something akin to a select statement?  If not, is there a way of using the value that's in that field to create multiple records like:

Q:\A_DPW\Images\SewerTieCards\<xsl:value-of select="FieldValue"/>.pdf
Q:\A_DPW\Images\WaterTieCards\<xsl:value-of select="FieldValue"/>.pdf
Q:\A_DPW\Images\AsBuilt\<xsl:value-of select="FieldValue"/>.pdf
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks Bob,
I'm able to get multiple blocks now - although they display as one line.  
I don't want to transform every field.  I think your idea of selecting a field with an XPath expression might be more of what I'm thinking of.  Is there a way that I could do something like this:

Select the Address Field:
<xsl:variable name="nameCol" select="FieldsDoc/Fields/Field/FieldName"/>="Address"

Create the table value:
             <a target="_blank">
                      <xsl:attribute name="href">
                        Q:\A_DPW\Images\WaterTieCards\<xsl:value-of select="FieldValue"/>.pdf
                      </xsl:attribute>
                      <xsl:value-of select="FieldValue"/>
                    </a>

And then repeat for each document?
Can you show me the output as it is now, and how you would like it to be?  I am a visual guy, and I can't "see" the problem.
Bob,
Here's the current output:
User generated imagehttps://www.experts-exchange.com/questions/28615711/XSL-HTML-GIS-PopUp-Referring-to-field-value.html#

...and I would prefer that it was like the following:

User generated image
...and, what is the input XML to the XSLT?
Bob,
I have to confess that I don't know what that means.
The XSLT transform has to work on something, so can you show me what that file/text is?
Bob,
This is where we may hit a wall.  This is within what's called an Esri GIS Arc Map document and I'm not sure how to reference the file.  I am guessing that the template refers to a file which is part of the database structure that is referenced by this part of the XSL code:

<xsl:variable name="nameCol" select="FieldsDoc/Fields/Field/FieldName"/>

and then moves through each of the field names and values (of course I may be wrong here).

In my first post I included the entire XSL Template.  Can you infer anything from that?

If not, do you know any one at experts-exchange that is familiar with GIS?

Jeff
1) Are you using ArcGIS for Desktop, or a different product?

2) What version are you working with?

3) I don't see that you are reading metadata, or there would be an esri namespace in the XSLT:

xmlns:esri="http://www.esri.com/metadata/"

4) Where do you store the XSLT file (in your project, in the ArcGIS folder, ...)?

5) Do you have a class/project that interfaces with ArcGIS?
Bob,
I'll get as many answers to you as I can early Monday.  Thanks for your help.
Jeff
Bob,
Here you go:
1. ArcGIS for Desktop
2. ArcMap 10.2.2
3. Got it
4. In the ArcMap document
5. What do you mean by class/project?

Thanks.
5.  Are you working directly with ArcGIS, or do you have another application that interfaces with it?

If you are working directly with ArcGIS, can you explain what you are doing, that you need to define a different XSLT output format?
I'm working directly with ArcGIS in a ArcMap Document.  The default XSL templates that were included list every attribute field (see ID: 40661413).  I don't need every attribute and I would like to use the same attribute field more than once.
Is this was you are working with?

XSLT Transformation (Conversion)
http://resources.arcgis.com/en/help/main/10.2/index.html#//001200000017000000

I am trying to figure out how you are working with the XSLT, so that I can get the proper context for the correct values.

Also, it has been a while since I have used ArcGIS, and I am thinking that they have changed the XSLT, so that it doesn't require the esri namespace.
Are you able to export the metadata as XML?

Export Metadata (Conversion)
http://resources.arcgis.com/en/help/main/10.1/index.html#//00120000000t000000
Bob,
I'm not sure I have the rights to export the metadata.  Instead I've implemented your recommendation in ID 40654570 and included carriage returns so that multiple results can be included and separated from each other.  I've also modified a portion of the code to suppress several fields that I don't need to see.  Here's the revised code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:msxsl="urn:schemas-microsoft-com:xslt">
	<xsl:variable name="ignoreFieldNames" select="'|OBJECTID|Shape|Shape_Length|Shape_Area|ATTACHMENTID|REL_OBJECTID|CONTENT_TYPE|ATT_NAME|DATA_SIZE|DATA|PlaceName|PlaceSub|City|State|Zip|Status|GIS_MapLotSuff|ASR_MapBlockLot|ASR_Address|UB_Address|Res_Address|ParentAddress|ParentMapBlockLot|Comments|GlobalID|PDFLink|DPW_Facility|OtherLink|DateIssued|SHAPE|created_user|created_date|last_edited_user|last_edited_date|StreetNum|StreetName|Unit|'"/>
	<xsl:variable name="headerRowColor" select="'#9CBCE2'"/>
	<xsl:variable name="alternateRowColor" select="'#D4E4F3'"/>
	<xsl:template match="/">
		<html>
			<head>
				<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
			</head>
			<body style="margin:0px 0px 0px 0px;overflow:auto;background:#FFFFFF;">
				<table style="font-family:Arial,Verdana,Times;font-size:12px;text-align:left;width:100%;border-collapse:collapse;padding:3px 3px 3px 3px">
					<tr style="text-align:center;font-weight:bold;background:{$headerRowColor}">
						<td>
							<xsl:value-of select="FieldsDoc/Title" />
						</td>
					</tr>
					<xsl:apply-templates select="FieldsDoc/Attachments" />
					<tr>
						<td>
							<table style="font-family:Arial,Verdana,Times;font-size:12px;text-align:left;width:100%;border-spacing:0px; padding:3px 3px 3px 3px">
								<xsl:choose>
									<xsl:when test="FieldsDoc/Fields/Field/FieldName">
										<xsl:apply-templates select="FieldsDoc/Fields/Field/FieldName[not(contains($ignoreFieldNames, concat(concat('|', text()), '|')))]/.." />
									</xsl:when>
									<xsl:otherwise>
										<xsl:apply-templates select="FieldsDoc/Fields/Field" />
									</xsl:otherwise>
								</xsl:choose>
							</table>
						</td>
					</tr>
				</table>
			</body>
		</html>
	</xsl:template>

	<xsl:template match="Attachments">
		<xsl:variable name="imageCount" select="count(Attachment/ContentType[contains(., 'image')])"/>
		<xsl:variable name="attachmentCount" select="count(Attachment)"/>
		<tr bgcolor="{$headerRowColor}">
			<td>
				<table style="font-family:Arial,Verdana,Times;font-size:12px;text-align:left;width:100%;border-spacing:0px; padding:3px 3px 3px 3px">
					<xsl:variable name="imageSrc" select="Attachment/ContentType[contains(., 'image')]/../FilePath"/>
					<xsl:if test="$imageSrc">
						<tr align="center">
							<td>
								<a target="_blank" href="{$imageSrc}">
									<img src="{$imageSrc}" width="275px" border="0"/>
								</a>
							</td>
						</tr>
						<tr align="center">
							<td>
								<xsl:value-of select="Attachment/ContentType[contains(., 'image')]/../Name" />
							</td>
						</tr>
					</xsl:if>
					<xsl:if test="($attachmentCount &gt; $imageCount) or not($imageCount = 1)">
						<tr align="center">
							<td>
								<table style="font-family:Arial,Verdana,Times;font-size:12px;text-align:left;width:100%;border-spacing:0px; padding:3px 3px 3px 3px">
									<xsl:for-each select="Attachment[position() mod 2 = 1]">
										<tr align="left" bgcolor="white">
											<xsl:if test="(position() +1) mod 2">
												<xsl:attribute name="bgcolor">
													<xsl:value-of select="$alternateRowColor"/>
												</xsl:attribute>
											</xsl:if>
											<td>
												<a target="_blank">
													<xsl:attribute name="href">
														<xsl:value-of select="FilePath"/>
													</xsl:attribute>
													<xsl:value-of select="Name" />
												</a>
											</td>
											<td>
												<a target="_blank">
													<xsl:attribute name="href">
														<xsl:value-of select="following-sibling::Attachment/FilePath"/>
													</xsl:attribute>
													<xsl:value-of select="following-sibling::Attachment/Name" />
												</a>
											</td>
										</tr>
									</xsl:for-each>
								</table>
							</td>
						</tr>
					</xsl:if>
				</table>
			</td>
		</tr>
	</xsl:template>

	<xsl:template match="Field">
		<tr>
			<xsl:if test="(position() +1) mod 2">
				<xsl:attribute name="bgcolor">
					<xsl:value-of select="$alternateRowColor"/>
				</xsl:attribute>
			</xsl:if>
			<xsl:if test="FieldName">
				<td>
					<xsl:value-of select="FieldName"/>
				</td>
			</xsl:if>
			<td>
				<xsl:choose>
					<xsl:when test="FieldName[starts-with(., 'Address')]">
						<a target="_blank"><xsl:attribute name="href">Q:\A_DPW\Images\WaterTieCards\<xsl:value-of select="FieldValue"/>.pdf
							</xsl:attribute>WaterTieCard
						</a>
						<BR></BR>
						<a target="_blank"><xsl:attribute name="href">Q:\A_DPW\Images\SewerTieCards\<xsl:value-of select="FieldValue"/>.pdf
							</xsl:attribute>SewerTieCard
						</a>
						<BR></BR>
						<a target="_blank"><xsl:attribute name="href">Q:\A_DPW\Images\SewerAsBuilts\"<xsl:value-of select="FieldValue"/>.pdf
							</xsl:attribute>SewerAsBuilt
						</a>
						<BR></BR>
						<a target="_blank"><xsl:attribute name="href">Q:\A_DPW\Images\Sewer House Connection Plans\<xsl:value-of select="FieldValue"/>.pdf
							</xsl:attribute>SewerHouseConnectionPlan
						</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 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(., '&lt;img ')]">
						<xsl:value-of select="FieldValue" disable-output-escaping="yes" />
					</xsl:when>
					<xsl:otherwise>
						<xsl:value-of select="FieldValue"/>
					</xsl:otherwise>
				</xsl:choose>
			</td>
		</tr>
	</xsl:template>
</xsl:stylesheet>

Open in new window

 

...and here's the result:
User generated image
...that gets me to a much better place than where I started.  Thanks for your help.

Jeff