在使用ESTK/InDesign导出时将XSLT应用于XML

Applying XSLT to XML while exporting with ESTK/InDesign

本文关键字:XSLT 应用于 XML ESTK InDesign      更新时间:2023-09-26

大家下午好,

我得到了一些帮助来设置这个结构,我使用它来基于XML结构中的某些XML元素动态地在桌面上创建一个文件夹,然后循环遍历XML记录,将它们分割成单独的文件,并将它们放入各自的文件夹中。到目前为止,它工作得很好,但是我需要应用一个XSL,它将某些属性转换为元素。在ESTK中是否有一种方法可以在导出时使用JavaScript应用XSLT ?

    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>

见答案:https://forums.adobe.com/thread/1813381

插入第13行前:

app.activeDocument.xmlExportPreferences.allowTransform=true;
app.activeDocument.xmlExportPreferences.transformFilename=File('PATH_TO_YOUR_TRANSFROM_FILE');