Auto Generated XML for Lists Format Suggestion

This forum allows users to post and respond to "How Do I Do ....." questions. The information contained in this forum has not been validated by K-Rise Systems and, as such, K-Rise Systems cannot guarantee the accuracy of the information.
Post Reply
JefferyD
Posts: 178
Joined: August 31st, 2021, 11:37 am
Contact:

Auto Generated XML for Lists Format Suggestion

Unread post by JefferyD »

The XML that gets generated when creating a new list in a widget and selecting the "Other" option can easily become quite large and difficult to maintain if any manual changes are needed. This is because it currently creates a copy of the XML structure for each column where the list is sorted by that column.
Adding List in Widget.png

Code: Select all

<xsl:variable name="SortField" select="WorkData/_Parameters/_Sort/Field"/>
<xsl:variable name="SortOrder" select="WorkData/_Parameters/_Sort/Order"/>
<xsl:variable name="StartIndex" select="WorkData/_Parameters/_Page/FromRecord"/>
<xsl:variable name="EndIndex" select="WorkData/_Parameters/_Page/FromRecord + WorkData/_Parameters/_Page/NoOfRecords"/>
<xsl:variable name="OrderBy">
	<xsl:choose>
		<xsl:when test="$SortOrder = ''">ascending</xsl:when>
		<xsl:when test="$SortOrder = 'ASC'">ascending</xsl:when>
		<xsl:when test="$SortOrder = 'asc'">ascending</xsl:when>
		<xsl:when test="$SortOrder = 'DESC'">descending</xsl:when>
		<xsl:when test="$SortOrder = 'desc'">descending</xsl:when>
		<xsl:otherwise>ascending</xsl:otherwise>
	</xsl:choose>
</xsl:variable>
<xsl:choose>
	<xsl:when test ="$SortField = 'UserName'">
		<xsl:for-each select="WorkData/GetUsers/Output/Result">
			<xsl:sort select="UserName" order="{$OrderBy}"/>
			<xsl:if test="position() >= $StartIndex and position() &lt;= $EndIndex">
				<Result>
					<UserName><xsl:value-of select="UserName"/></UserName>
					<Age><xsl:value-of select="Age"/></Age>
					<UserType><xsl:value-of select="UserType"/></UserType>
					<Manager><xsl:value-of select="Manager"/></Manager>
					<PhoneNumber><xsl:value-of select="PhoneNumber"/></PhoneNumber>
					<EmailAddress><xsl:value-of select="EmailAddress"/></EmailAddress>
					<Status><xsl:value-of select="Status"/></Status>
				</Result>
			</xsl:if>
		</xsl:for-each>
	</xsl:when>
	<xsl:when test ="$SortField = 'Age'">
		<xsl:for-each select="WorkData/GetUsers/Output/Result">
			<xsl:sort select="Age" order="{$OrderBy}"/>
			<xsl:if test="position() >= $StartIndex and position() &lt;= $EndIndex">
				<Result>
					<UserName><xsl:value-of select="UserName"/></UserName>
					<Age><xsl:value-of select="Age"/></Age>
					<UserType><xsl:value-of select="UserType"/></UserType>
					<Manager><xsl:value-of select="Manager"/></Manager>
					<PhoneNumber><xsl:value-of select="PhoneNumber"/></PhoneNumber>
					<EmailAddress><xsl:value-of select="EmailAddress"/></EmailAddress>
					<Status><xsl:value-of select="Status"/></Status>
				</Result>
			</xsl:if>
		</xsl:for-each>
	</xsl:when>
	<xsl:when test ="$SortField = 'UserType'">
		<xsl:for-each select="WorkData/GetUsers/Output/Result">
			<xsl:sort select="UserType" order="{$OrderBy}"/>
			<xsl:if test="position() >= $StartIndex and position() &lt;= $EndIndex">
				<Result>
					<UserName><xsl:value-of select="UserName"/></UserName>
					<Age><xsl:value-of select="Age"/></Age>
					<UserType><xsl:value-of select="UserType"/></UserType>
					<Manager><xsl:value-of select="Manager"/></Manager>
					<PhoneNumber><xsl:value-of select="PhoneNumber"/></PhoneNumber>
					<EmailAddress><xsl:value-of select="EmailAddress"/></EmailAddress>
					<Status><xsl:value-of select="Status"/></Status>
				</Result>
			</xsl:if>
		</xsl:for-each>
	</xsl:when>
	<xsl:when test ="$SortField = 'Manager'">
		<xsl:for-each select="WorkData/GetUsers/Output/Result">
			<xsl:sort select="Manager" order="{$OrderBy}"/>
			<xsl:if test="position() >= $StartIndex and position() &lt;= $EndIndex">
				<Result>
					<UserName><xsl:value-of select="UserName"/></UserName>
					<Age><xsl:value-of select="Age"/></Age>
					<UserType><xsl:value-of select="UserType"/></UserType>
					<Manager><xsl:value-of select="Manager"/></Manager>
					<PhoneNumber><xsl:value-of select="PhoneNumber"/></PhoneNumber>
					<EmailAddress><xsl:value-of select="EmailAddress"/></EmailAddress>
					<Status><xsl:value-of select="Status"/></Status>
				</Result>
			</xsl:if>
		</xsl:for-each>
	</xsl:when>
	<xsl:when test ="$SortField = 'PhoneNumber'">
		<xsl:for-each select="WorkData/GetUsers/Output/Result">
			<xsl:sort select="PhoneNumber" order="{$OrderBy}"/>
			<xsl:if test="position() >= $StartIndex and position() &lt;= $EndIndex">
				<Result>
					<UserName><xsl:value-of select="UserName"/></UserName>
					<Age><xsl:value-of select="Age"/></Age>
					<UserType><xsl:value-of select="UserType"/></UserType>
					<Manager><xsl:value-of select="Manager"/></Manager>
					<PhoneNumber><xsl:value-of select="PhoneNumber"/></PhoneNumber>
					<EmailAddress><xsl:value-of select="EmailAddress"/></EmailAddress>
					<Status><xsl:value-of select="Status"/></Status>
				</Result>
			</xsl:if>
		</xsl:for-each>
	</xsl:when>
	<xsl:when test ="$SortField = 'EmailAddress'">
		<xsl:for-each select="WorkData/GetUsers/Output/Result">
			<xsl:sort select="EmailAddress" order="{$OrderBy}"/>
			<xsl:if test="position() >= $StartIndex and position() &lt;= $EndIndex">
				<Result>
					<UserName><xsl:value-of select="UserName"/></UserName>
					<Age><xsl:value-of select="Age"/></Age>
					<UserType><xsl:value-of select="UserType"/></UserType>
					<Manager><xsl:value-of select="Manager"/></Manager>
					<PhoneNumber><xsl:value-of select="PhoneNumber"/></PhoneNumber>
					<EmailAddress><xsl:value-of select="EmailAddress"/></EmailAddress>
					<Status><xsl:value-of select="Status"/></Status>
				</Result>
			</xsl:if>
		</xsl:for-each>
	</xsl:when>
	<xsl:when test ="$SortField = 'Status'">
		<xsl:for-each select="WorkData/GetUsers/Output/Result">
			<xsl:sort select="Status" order="{$OrderBy}"/>
			<xsl:if test="position() >= $StartIndex and position() &lt;= $EndIndex">
				<Result>
					<UserName><xsl:value-of select="UserName"/></UserName>
					<Age><xsl:value-of select="Age"/></Age>
					<UserType><xsl:value-of select="UserType"/></UserType>
					<Manager><xsl:value-of select="Manager"/></Manager>
					<PhoneNumber><xsl:value-of select="PhoneNumber"/></PhoneNumber>
					<EmailAddress><xsl:value-of select="EmailAddress"/></EmailAddress>
					<Status><xsl:value-of select="Status"/></Status>
				</Result>
			</xsl:if>
		</xsl:for-each>
	</xsl:when>
	<xsl:otherwise>
		<xsl:for-each select="WorkData/GetUsers/Output/Result">
			<xsl:if test="position() >= $StartIndex and position() &lt;= $EndIndex">
				<Result>
					<UserName><xsl:value-of select="UserName"/></UserName>
					<Age><xsl:value-of select="Age"/></Age>
					<UserType><xsl:value-of select="UserType"/></UserType>
					<Manager><xsl:value-of select="Manager"/></Manager>
					<PhoneNumber><xsl:value-of select="PhoneNumber"/></PhoneNumber>
					<EmailAddress><xsl:value-of select="EmailAddress"/></EmailAddress>
					<Status><xsl:value-of select="Status"/></Status>
				</Result>
			</xsl:if>
		</xsl:for-each>
	</xsl:otherwise>
</xsl:choose>
Generated List XML.txt
(6.45 KiB) Downloaded 196 times
Generated List XML.txt
(6.45 KiB) Downloaded 196 times


Alternate Suggested Format
I created the following format from the current one that, while a little more advanced, I believe is easier to read and make changes to.
  • Summary of Changes:
    • Simplified sorting direction choose logic
      • EASYProcess:ToLower($SortOrder) could be replaced with translate($SortOrder, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')
    • Added data-type to sorting configurable for each column
      • I would expect them all to default to "text", but my example includes a "number" to show one of the reasons I added this
    • Reworked XML structure as a single for-each and moved sort column choose logic to variable

Code: Select all

<xsl:variable name="SortField" select="WorkData/_Parameters/_Sort/Field"/>
<xsl:variable name="SortOrder" select="WorkData/_Parameters/_Sort/Order"/>
<xsl:variable name="StartIndex" select="WorkData/_Parameters/_Page/FromRecord"/>
<xsl:variable name="EndIndex" select="WorkData/_Parameters/_Page/FromRecord + WorkData/_Parameters/_Page/NoOfRecords"/>
<xsl:variable name="OrderDirection">
	<xsl:choose>
		<xsl:when test="EASYProcess:ToLower($SortOrder) = 'desc'">descending</xsl:when>
		<xsl:otherwise>ascending</xsl:otherwise>
	</xsl:choose>
</xsl:variable>
<xsl:variable name="OrderBy">
	<xsl:choose>
		<xsl:when test="$SortField = 'UserName'">UserNameValue</xsl:when>
		<xsl:when test="$SortField = 'Age'">AgeValue</xsl:when>
		<xsl:when test="$SortField = 'UserType'">UserTypeValue</xsl:when>
		<xsl:when test="$SortField = 'Manager'">ManagerValue</xsl:when>
		<xsl:when test="$SortField = 'PhoneNumber'">PhoneNumberValue</xsl:when>
		<xsl:when test="$SortField = 'EmailAddress'">EmailAddressValue</xsl:when>
		<xsl:when test="$SortField = 'Status'">StatusValue</xsl:when>
		<xsl:otherwise></xsl:otherwise>
	</xsl:choose>
</xsl:variable>
<xsl:variable name="SortType">
	<xsl:choose>
		<xsl:when test="$SortField = 'UserName'">text</xsl:when>
		<xsl:when test="$SortField = 'Age'">number</xsl:when>
		<xsl:when test="$SortField = 'UserType'">text</xsl:when>
		<xsl:when test="$SortField = 'Manager'">text</xsl:when>
		<xsl:when test="$SortField = 'PhoneNumber'">text</xsl:when>
		<xsl:when test="$SortField = 'EmailAddress'">text</xsl:when>
		<xsl:when test="$SortField = 'Status'">text</xsl:when>
		<xsl:otherwise>text</xsl:otherwise>
	</xsl:choose>
</xsl:variable>

<xsl:for-each select="WorkData/GetUsers/Output/Result">
	<xsl:sort select="*[name()=$OrderBy]" order="{$OrderDirection}" data-type="{$SortType}"/>
	<xsl:if test="position() >= $StartIndex and position() &lt;= $EndIndex">
		<Result>
			<UserName><xsl:value-of select="UserName"/></UserName>
			<BirthDate><xsl:value-of select="Age"/></BirthDate>
			<UserType><xsl:value-of select="UserType"/></UserType>
			<Manager><xsl:value-of select="Manager"/></Manager>
			<PhoneNumber><xsl:value-of select="PhoneNumber"/></PhoneNumber>
			<EmailAddress><xsl:value-of select="EmailAddress"/></EmailAddress>
			<Status><xsl:value-of select="Status"/></Status>
		</Result>
	</xsl:if>
</xsl:for-each>
Suggested List XML.txt
(2.35 KiB) Downloaded 182 times
Suggested List XML.txt
(2.35 KiB) Downloaded 182 times
word count: 1264

Tags:
SteveCap
Posts: 329
Joined: August 26th, 2021, 9:18 am
Contact:

Re: Auto Generated XML for Lists Format Suggestion

Unread post by SteveCap »

This change has already been made in task #9958 when it has been released this post will be updated.
word count: 19
JustinVanRegenmorter
Posts: 571
Joined: August 26th, 2021, 9:56 am
Contact:

Re: Auto Generated XML for Lists Format Suggestion

Unread post by JustinVanRegenmorter »

This suggestion is implemented in the current version of EASYProcess.
word count: 10
Post Reply