Usefull XSLT for Submit point XML
Posted: Fri Oct 18, 2024 9:55 am
I had a case where I needed a lot of values from a Submit point and I thought that it would be a better way to show this XML.
So I asked ChatGPT for a better one, after a few tries we got this and it has only the usable fields.
It will give you a much simpler XML looking like this:
Note that this case uses a straight submit point without any sub-fields. If so it needs a little more in the XSLT, but ChatGPT will help you fix that.
So I asked ChatGPT for a better one, after a few tries we got this and it has only the usable fields.
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<!-- Root element -->
<xsl:template match="/field-list">
<order>
<orderRows>
<!-- Process each field -->
<xsl:apply-templates select="field"/>
</orderRows>
</order>
</xsl:template>
<!-- Template to transform each field into a row -->
<xsl:template match="field">
<row>
<!-- Add the tag as the name attribute -->
<xsl:attribute name="name">
<xsl:value-of select="tag"/>
</xsl:attribute>
<!-- The content inside the row will be the value -->
<xsl:value-of select="value"/>
</row>
</xsl:template>
</xsl:stylesheet>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<order>
<orderRows>
<row name="Order name">116166</row>
<row name="Quantity">1</row>
<row name="Product type">FlatWork</row>
<row name="Part type">Leaflet</row>
<row name="Part name">Motiv 3 C</row>
<row name="Part ordning nr">3</row>
<row name="Bleed">5</row>
<row name="Page width">320</row>
<row name="Page height">246</row>
<row name="Final page width">520</row>
<row name="Final page height">248</row>
<row name="Pages">1</row>
<row name="Spread type">SinglePage</row>
</orderRows>
</order>