IIRC What you want to use is an XSLT on an XML document. My memory is a bit rusty on this.
You’d first want to export an XML document that has the scene graph, the artboard or the scene node into an XML representation. So something like this:
<SceneNode type="Artboard">
<SceneNode x="10" y="10" type="Rectangle" fill="rgba(0,0,0,1)"/>
</SceneNode>
Then you have created a XSL or XSLT document that describes how to translate that document into another document (example XSLT found online):
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/persons">
<root>
<xsl:apply-templates select="person"/>
</root>
</xsl:template>
<xsl:template match="person">
<name type="{@username}">
<xsl:value-of select="name" />
</name>
</xsl:template>
</xsl:stylesheet>
You would then give both of those to a XML document processor and it would “translate” from one XML markup type to another. Web browsers like Firefox and Chrome have XSL processors built in.
The UXP architecture is sort of kind of an HTML browser but doesn’t support all the features browsers do. XML processing is not one of them (that I’m aware of).
How to transform XML to XML using XSLT.
Since XML transforms aren’t supported (yet?) in UXP I would do three things:
- Make a feature request here on the forums
- If you make a plugin yourself see below
- See if it’s already done or could be added to an existing plugin
If you do it yourself you can create the XML in the plugin and then post or send that XML to a web server or web page you have setup that would use the browser to transform your XML using your XSLT stylesheet.
Sometimes companies already have markup in XML format and already have XSLT stylesheets so check with Autodesk.
But if you’re writing XML in the first place why not write it into the XML as you want it to be and skipping the XSLT? The code you posted doesn’t look like XML but more like JSON.
Some caveats: IIRC some developers have issues with XSLT in that it has some learning curve or some issues?
There are more examples online for “how to transform xml using xslt”.