Usefull XSLT for Submit point XML

Post Reply
jan_suhr
Advanced member
Posts: 687
Joined: Fri Nov 04, 2011 1:12 pm
Location: Nyköping, Sweden

Usefull XSLT for Submit point XML

Post 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.
Jan Suhr
Color Consult AB
Sweden
=============
Check out my apps
freddyp
Advanced member
Posts: 1130
Joined: Thu Feb 09, 2012 3:53 pm

Re: Usefull XSLT for Submit point XML

Post 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">
User avatar
tdeschampsBluewest
Member
Posts: 132
Joined: Tue Jun 01, 2021 11:57 am

Re: Usefull XSLT for Submit point XML

Post 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 ;)
Do you like the Enfocus Apps developed by Bluewest?
Feel free to leave a comment on the Appstore!
Post Reply