Page 1 of 1

Usefull XSLT for Submit point XML

Posted: Fri Oct 18, 2024 9:55 am
by jan_suhr
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.

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>
It will give you a much simpler XML looking like this:

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>
      
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.

Re: Usefull XSLT for Submit point XML

Posted: Tue Oct 22, 2024 1:17 pm
by freddyp
Thanks for sharing this, Jan.

Not tested, but the modification to make sure all dependent fields are processed too, will be to replace:

Code: Select all

<!-- Root element -->
<xsl:template match="/field-list">
by

Code: Select all

<!-- All field-list elements -->
<xsl:template match="//field-list">

Re: Usefull XSLT for Submit point XML

Posted: Fri Oct 25, 2024 9:47 pm
by tdeschampsBluewest
Hello Jan,

We had the same issue and developed Switch XML Simplify specifically to address it.
it works right out of the box, maintaining nested variables with proper indentation or flattening everything if needed.

We now use it in every new project involving a Switch client, It’s a paid app, but saving time for users during integration is really worth the price.

On a side note, it also works with Connect All XML ;)