XSLT Transformation  / Thumbnails

Discussion created by cpoynter on Jun 18, 2013
Latest reply on Sep 18, 2013 by cpoynter
Hi All,

I have two issues. I am running ArcGIS 10.1 Windows 7 64 bit (those are not the issues - hopefully).

1) I am trying to use the XSLT Transformation Conversion but outside of ArcGIS Python window it does not run. IDLE / PyScripter just hang at this section of code. Same code runs fine within the python window of ArcGIS 10.1;

2) I have a number of thumbnails that I have created that I would like to utilise in the the created HTML pages produced by a functioning XSLT Transformation Conversion, but don't know how to get them into the output HTML.

I believe the thumbnails need to be incorporated at some point into metadata files for my datasets, so I guess I am missing a section of code relating to editing metadata.

Following is my code:

## 1) Create a blank MXD
## 2) Loop through data and add to MXD to export Thumbnails
## 3) Create HTML metadata pages incorporating Thumbnails

import arcpy, os, json, traceback, sys, datetime
from arcpy import mapping
from arcpy import env

mxd_out = r'D:\Temp\HTML.mxd'

now = datetime.datetime.now()
log = r'D:\Temp\CSD_HTML\Invertory_' + now.strftime("%Y-%m-%d" + '_' + "%H_%M_%S") + '_Error.log'

if arcpy.Exists(log):

if arcpy.Exists(mxd_out):

mapService = {}
jsonDump = json.dumps(mapService)
result = mapping.ConvertWebMapToMapDocument(jsonDump)
mxd = result.mapDocument
my_mxd = mxd.saveACopy(mxd_out)

env.workspace = r"D:\Temp\Data"

contents = []

print 'Starting'

for dirpath, dirnames, datatypes in arcpy.da.Walk(env.workspace):

        for item in contents:
            if arcpy.Exists(item):

                arcpy.env.workspace = item

        listType = [arcpy.ListFeatureClasses, arcpy.ListDatasets]
        for list in listType:

            datasetList = list("*", 'All')

            # Iterate over the feature classes
            for dataset in datasetList:

                    data = item + '\\' + dataset

                    desc = arcpy.Describe(data)

                    print data + ' : ' + desc.dataType

                    # Crack open the map
                    mxd_new = arcpy.mapping.MapDocument(mxd_out)

                    df = arcpy.mapping.ListDataFrames(mxd_new, '*')[0]


                            lyrFile = arcpy.mapping.Layer(data)

                            if desc.dataType == 'RasterDataset':
                                layerType = arcpy.management.MakeRasterLayer

                                result = layerType(lyrFile, 'temp_layer')
                                layer_object = result.getOutput(0)
                                arcpy.mapping.AddLayer(df, layer_object)

                                result = arcpy.management.MakeFeatureLayer(lyrFile, 'temp_layer')
                                layer_object = result.getOutput(0)
                                arcpy.mapping.AddLayer(df, layer_object)

                            # Set correct extent

                            nm = os.path.splitext(dataset)[0]

                            # Compute an output file name
                            out_file_name = (r"D:\Temp\Thumbs" + "\\" + nm + '.jpg')

                            # Export "thumbnail" of data frame
                            arcpy.mapping.ExportToJPEG(mxd_new, out_file_name, df, 300, 300)

                            # Pull the layer out of the data frame to make room for the next one
                            arcpy.mapping.RemoveLayer(df, layer_object)

                            # Delete the GP layer

                            #set local variables
                            dir = arcpy.GetInstallInfo("desktop")["InstallDir"]
                            xslt = dir + "Metadata/Stylesheets/ArcGIS.xsl"
                            arcpy.XSLTransform_conversion(data, xslt, r'D:\Temp' + '\\' + nm + '.html', out_file_name)

##                            xslt = r"C:\Program Files (x86)\ArcGIS\Desktop10.1\Metadata\Stylesheets\ArcGIS.xsl"
##                            arcpy.XSLTransform_conversion(data, xslt, r'D:\Temp' + '\\' + nm + '.html', out_file_name)


                        f=open(log, 'at')
                        f.write(data + '\n')

del mxd, mxd_new

if arcpy.Exists(mxd_out):

del mxd_out

Guidance greatly appreciated.