4

How to add Video in HTML Popup on ArcMap? It said using xsl, but I just don't get it.. try to find tutorial but no luck

I use template codes :

<?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(., '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>

I create field called VIDEO and put sample video link such as "youtube.com/watch?v=lncOvjE4Fko", but when I click html popup nothing happened, it shows blank on video field. No tutorial or explanation further about adding video on HTML popup. (I already load the template from source given above, and mark "as a formated page based on an XSL Template")

11
  • The help says "For XSL template examples, refer to the HTMLPopup folder in the <install drive>:\Program Files\ArcGIS"
    – PolyGeo
    Commented Jul 31, 2016 at 12:23
  • already tried but no luck, I create field called VIDEO and put sample video link such as "youtube.com/watch?v=lncOvjE4Fko", but when I click html popup nothing happened, it shows blank on video field. No tutorial or explanation further about adding video on HTML popup. (I already load the template from source given above, and mark "as a formated page based on an XSL Template") Commented Jul 31, 2016 at 12:26
  • edited question Commented Jul 31, 2016 at 12:40
  • can you show the code you added in your template?
    – nmtoken
    Commented Jul 31, 2016 at 13:22
  • sure, Actually I use Arcmap xsl template code from style "Embed Video" Commented Jul 31, 2016 at 13:45

2 Answers 2

5
+50

You are on the right track with XLS, however when working with YouTube videos in HTML you need to use an <iframe> to display the video. The <object> and <embed> tag combination only works with video that have not been encode through YouTube or other video service, for example: mp4, Adobe Flash, or ogg.

  1. Rewrite the URL from https://www.youtube.com/watch?v=lncOvjE4Fko to https://www.youtube.com/embed/lncOvjE4FkoThis will allow the video to be played natively in the popup.
  2. If you want the video to start automatically when the page loads add ?autoplay=1 to the end of the URL.
  3. Replace the piece of code <object width="425" height="355">...</object> and put in the following:

<iframe id="ytplayer" type="text/html" width="640" height="390" src="**URL_GOES_HERE**" frameborder="0"></iframe>

The width and height can be change to be what ever works best for your size of popup, if you use 100% for both height and width it will auto size to window size.

Now when you open the popup the <iframe> will load the video and you should see the play button or if you added the ?autoplay=1 parameter in the URL it will start playing automatically.

Here is your code with the field name VIDEO check in the XLS 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" 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|'"/>
 <xsl:template match="/">
  <html>
   <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
   </head>
   <body>
    <table>
     <tr style="text-align:center;font-weight:bold;background:">
     </tr>
     <xsl:apply-templates select="FieldsDoc/Attachments" />
     <tr>
      <td>
       <table>
        <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="Field">
  <tr>

   <xsl:if test="FieldName">
    <td>
     <xsl:value-of select="FieldName"/>
    </td>
   </xsl:if>
   <td>
    <xsl:choose>
     <xsl:when test="FieldName[starts-with(., 'VIDEO')]">
       <iframe id="ytplayer" type="text/html" width="640" height="390" frameborder="0">
       <xsl:attribute name="src"><xsl:value-of select="FieldValue"/>
       </xsl:attribute>
       <xsl:value-of select="FieldValue"/>
      </iframe>
     </xsl:when>
     <xsl:otherwise>
      <xsl:value-of select="FieldValue"/>
     </xsl:otherwise>
    </xsl:choose>
   </td>
  </tr>
 </xsl:template>
</xsl:stylesheet>
8
  • I have followed your direction, but still nothing happened, I dont know what's wrong with this thing..., please help me check it prntscr.com/c3ruqh Commented Aug 10, 2016 at 1:35
  • Please see edit above and give it a try.
    – dpw4050
    Commented Aug 11, 2016 at 5:26
  • as you see in prntscr.com/c49hf1 after I did based on your edited script nothing happened.... Commented Aug 11, 2016 at 5:36
  • In ArcMap you do need to save the mxd and re-open to load any changes in the xls template, very annoying. When I open it the iframe is loading.
    – dpw4050
    Commented Aug 11, 2016 at 5:43
  • Yes, it's really annoying, really... and you deserve to have the bounty. If possible (if you don't mind) all my pictures are not displayed after I use xls, any clue? Commented Aug 11, 2016 at 5:57
-4

Please show you code? When we help you quickly.

Are you replace to:

<td>    
    <xsl:if test="string-length($nameCol) != 0">
        <xsl:for-each select="FieldsDoc/Fields/Field">      
            <xsl:choose>
                <xsl:when test="FieldName='VIDEO'">
                    <xsl:value-of select="FieldValue"  disable-output-escaping="yes" /> 
                </xsl:when>
            </xsl:choose>          
        </xsl:for-each>
    </xsl:if>
</td>
3
  • Besides (but i don't sure) your ever line should start with 'VIDEO'
    – GRM
    Commented Aug 10, 2016 at 10:07
  • 1
    Is this an answer or follow-up questions for the OP?
    – Aaron
    Commented Aug 10, 2016 at 12:12
  • I already show my code and what do you mean with ever line? Commented Aug 10, 2016 at 16:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.