0

Good afternoon Scripters,

I have had some help setting up this structure, which I am using to create a folder on my desktop dynamically based on certain XML elements in my XML strucure, then loop through the XML records, split them into separate files, and put them in their respective folders. So far, it is working perfectly, but I need to apply an XSL that I have which will convert certain attributes into elements. Is there a way in ESTK to apply XSLT with JavaScript upon export?

    var root, records, f, n, doc;

        doc = app.activeDocument;
        root = doc.xmlElements[0];
        records = root.evaluateXPathExpression ( "./record" );
        n = records.length;
        while ( n-- ) {
                var ff = new Folder(Folder.desktop + "/" +app.activeDocument.xmlElements.item(0).xmlElements.item(n).xmlElements.item(0).xmlAttributes.item(0).value + "/data/" + 
                                        app.activeDocument.xmlElements.item(0).xmlElements.item(n).xmlElements.item(0).xmlElements.item(0).xmlElements.item(1).xmlAttributes.item(1).value  + "/" +
                                        app.activeDocument.xmlElements.item(0).xmlElements.item(n).xmlElements.item(0).xmlElements.item(0).xmlElements.item(2).xmlAttributes.item(1).value);
        if (!ff.exists)
            ff.create();

            f = File ( ff +"/"+app.activeDocument.xmlElements.item(0).xmlElements.item(n).xmlElements.item(0).xmlElements.item(0).xmlElements.item(0).xmlAttributes.item(1).value);
            records[n].exportFile ( ExportFormat.XML, f);
        }

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">



                <xsl:for-each select="Root/record">
                        <record name="{@name}" type="{@type}">
                            <item name="{item/@name}">
                                <value>
                                    <xsl:for-each select="item/value/item">
                                    <item name="{@name}">
                                    <value><xsl:value-of select="@value"/></value>
                                    </item>
                                    </xsl:for-each>
                                </value>    
                            </item>     
                        </record>
                    </xsl:for-each>

</xsl:template>

</xsl:stylesheet>
Natetown
  • 1
  • 1

1 Answers1

1

See answer here: https://forums.adobe.com/thread/1813381

insert before line 13:

app.activeDocument.xmlExportPreferences.allowTransform=true;
app.activeDocument.xmlExportPreferences.transformFilename=File('PATH_TO_YOUR_TRANSFROM_FILE');
user1754036
  • 396
  • 1
  • 6
  • I ended up just modifying my JavaScript to do the changes instead of using an XSLT spreadsheet. Thank you for your response! – Natetown Sep 08 '15 at 14:29