Author |
Message
|
Simbu |
Posted: Fri Jul 26, 2013 1:35 am Post subject: Sorting in Message Broker using XSL |
|
|
 Master
Joined: 17 Jun 2011 Posts: 289 Location: Tamil Nadu, India
|
Hi All,
My requirement is to sort multiple elements in the repeating complex elements in message broker and finally send all records in a file in fixed format to destination system.
My Input XML is as below
Code: |
<Items>
<ItemLoc>
<location>5</location>
<class>2</class>
<item>2</item>
</ItemLoc>
<ItemLoc>
<location>5</location>
<class>1</class>
<item>1</item>
</ItemLoc>
<ItemLoc>
<location>2</location>
<class>6</class>
<item>10</item>
</ItemLoc>
<ItemLoc>
<location>2</location>
<class>7</class>
<item>11</item>
</ItemLoc>
<ItemLoc>
<location>2</location>
<class>7</class>
<item>5</item>
</ItemLoc>
</Items> |
First I need to sort all the records based on the location in ItemLoc and with location as a reference, I need to sort by class under each same location and finally sort the items under same class and finally my Output XML should be like below
Code: |
<Items>
<ItemLoc>
<location>2</location>
<class>6</class>
<item>10</item>
</ItemLoc>
<ItemLoc>
<location>2</location>
<class>7</class>
<item>5</item>
</ItemLoc>
<ItemLoc>
<location>2</location>
<class>7</class>
<item>11</item>
</ItemLoc>
<ItemLoc>
<location>5</location>
<class>1</class>
<item>1</item>
</ItemLoc>
<ItemLoc>
<location>5</location>
<class>2</class>
<item>2</item>
</ItemLoc>
</Items> |
I tried with XSL to do this sorting and it is working fine
Code: |
<Items>
<xsl:for-each select="Items/ItemLoc">
<xsl:sort select="location" data-type="number"/>
<xsl:sort select="class" data-type="number"/>
<xsl:sort select="item" data-type="number"/>
<xsl:copy-of select="." />
</xsl:for-each>
</Items>
|
My Broker and Toolkit version is 8.0.0.2 running on windows
Please share your comments on whether using XSL is best approach for Sorting or not in message broker. |
|
Back to top |
|
 |
mqjeff |
Posted: Fri Jul 26, 2013 2:07 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
It's easy enough to write an insertion sort in ESQL to build the output tree in sorted order.
It's twice as easy to use the sorting facilities in the Graphical Data Mapper in v8 and later. |
|
Back to top |
|
 |
Simbu |
Posted: Fri Jul 26, 2013 8:36 am Post subject: |
|
|
 Master
Joined: 17 Jun 2011 Posts: 289 Location: Tamil Nadu, India
|
Thanks for the suggestion. Can you please show some lights on how to use Graphical Data Mapper for sorting. |
|
Back to top |
|
 |
lancelotlinc |
Posted: Fri Jul 26, 2013 9:21 am Post subject: |
|
|
 Jedi Knight
Joined: 22 Mar 2010 Posts: 4941 Location: Bloomington, IL USA
|
|
Back to top |
|
 |
mqjeff |
Posted: Fri Jul 26, 2013 9:56 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
|
Back to top |
|
 |
Simbu |
Posted: Sat Jul 27, 2013 2:33 am Post subject: |
|
|
 Master
Joined: 17 Jun 2011 Posts: 289 Location: Tamil Nadu, India
|
Thanks for the links. I achieved sorting using "Sort" property but nothing found about the "Sort property" in InfoCenter. |
|
Back to top |
|
 |
mqsiuser |
Posted: Tue Aug 06, 2013 12:56 am Post subject: |
|
|
 Yatiri
Joined: 15 Apr 2008 Posts: 637 Location: Germany
|
mqjeff wrote: |
It's easy enough to write an insertion sort in ESQL to build the output tree |
I don't understand when people suggest alternatives to something that has been thoroughly discussed before. To properly implement ESQL-Sorting: Its not trivial (to consider all constraints) and best of all... it has been done before. If you found something (much) better post the relevant parts (of your insertion-sort algorithm) so we can review it.
And XSLT-Sorting can lead to memory consumption problems (as stated in one of the threads in this forum).
And ofc. if you can be wasteful with resources you can do so. _________________ Just use REFERENCEs |
|
Back to top |
|
 |
dogorsy |
Posted: Tue Aug 06, 2013 1:53 am Post subject: |
|
|
Knight
Joined: 13 Mar 2013 Posts: 553 Location: Home Office
|
mqsiuser wrote: |
mqjeff wrote: |
It's easy enough to write an insertion sort in ESQL to build the output tree |
I don't understand when people suggest alternatives to something that has been thoroughly discussed before. To properly implement ESQL-Sorting: Its not trivial (to consider all constraints) and best of all... it has been done before. If you found something (much) better post the relevant parts (of your insertion-sort algorithm) so we can review it.
And XSLT-Sorting can lead to memory consumption problems (as stated in one of the threads in this forum).
And ofc. if you can be wasteful with resources you can do so. |
it would be nice to have ORDER BY in ESQL SELECT |
|
Back to top |
|
 |
smdavies99 |
Posted: Tue Aug 06, 2013 2:08 am Post subject: |
|
|
 Jedi Council
Joined: 10 Feb 2003 Posts: 6076 Location: Somewhere over the Rainbow this side of Never-never land.
|
[quote="dogorsy"
it would be nice to have ORDER BY in ESQL SELECT[/quote]
you could always create an improvement request??????
 _________________ WMQ User since 1999
MQSI/WBI/WMB/'Thingy' User since 2002
Linux user since 1995
Every time you reinvent the wheel the more square it gets (anon). If in doubt think and investigate before you ask silly questions. |
|
Back to top |
|
 |
mqsiuser |
Posted: Tue Aug 06, 2013 3:33 am Post subject: |
|
|
 Yatiri
Joined: 15 Apr 2008 Posts: 637 Location: Germany
|
Message Transformation is different than Databases!
Nothing better could happen than to have ESQL.
And sort implemented within it
I am looking forward to mqjeff's reply. _________________ Just use REFERENCEs |
|
Back to top |
|
 |
dogorsy |
Posted: Tue Aug 06, 2013 3:49 am Post subject: |
|
|
Knight
Joined: 13 Mar 2013 Posts: 553 Location: Home Office
|
mqsiuser wrote: |
I am looking forward to mqjeff's reply. |
or mgk's !
order by for database selects is easy, just pass it on to the DB. So WMB should implement it only for Select from message tree. |
|
Back to top |
|
 |
smdavies99 |
Posted: Tue Aug 06, 2013 4:06 am Post subject: |
|
|
 Jedi Council
Joined: 10 Feb 2003 Posts: 6076 Location: Somewhere over the Rainbow this side of Never-never land.
|
dogorsy wrote: |
order by for database selects is easy, just pass it on to the DB. So WMB should implement it only for Select from message tree. |
This is not possible in some sites because PASSTHRU is banned because some IBM consultant (Global Services) once said that it was not 'best practice'.
Now wheres the Ostrich-with-head-in-sand Emoticon when you need it? _________________ WMQ User since 1999
MQSI/WBI/WMB/'Thingy' User since 2002
Linux user since 1995
Every time you reinvent the wheel the more square it gets (anon). If in doubt think and investigate before you ask silly questions. |
|
Back to top |
|
 |
dogorsy |
Posted: Tue Aug 06, 2013 5:23 am Post subject: |
|
|
Knight
Joined: 13 Mar 2013 Posts: 553 Location: Home Office
|
smdavies99 wrote: |
dogorsy wrote: |
order by for database selects is easy, just pass it on to the DB. So WMB should implement it only for Select from message tree. |
This is not possible in some sites because PASSTHRU is banned because some IBM consultant (Global Services) once said that it was not 'best practice'.
Now wheres the Ostrich-with-head-in-sand Emoticon when you need it? |
Sorry, I think you misunderstood my post, I was talking about implementing ESQL SELECT ORDER BY, I said for ESQL SELECT from database it would be easy to implement, just syntax check and pass it to the database, I never mentioned PASSTHRU. |
|
Back to top |
|
 |
kash3338 |
Posted: Tue Aug 06, 2013 5:58 am Post subject: |
|
|
Shaman
Joined: 08 Feb 2009 Posts: 709 Location: Chennai, India
|
dogorsy wrote: |
Sorry, I think you misunderstood my post, I was talking about implementing ESQL SELECT ORDER BY, I said for ESQL SELECT from database it would be easy to implement, just syntax check and pass it to the database, I never mentioned PASSTHRU. |
The above point is not so clear.
You mean ESQL SELECT ORDER BY? There is no ORDER BY in ESQL, you need PASSTHRU to implement one.
The point made by smdavies99 is that to implement ORDER BY in ESQL, you need to use PASSTHRU and that is not used ta many places. |
|
Back to top |
|
 |
lancelotlinc |
Posted: Tue Aug 06, 2013 6:04 am Post subject: |
|
|
 Jedi Knight
Joined: 22 Mar 2010 Posts: 4941 Location: Bloomington, IL USA
|
kash3338 wrote: |
dogorsy wrote: |
Sorry, I think you misunderstood my post, I was talking about implementing ESQL SELECT ORDER BY, I said for ESQL SELECT from database it would be easy to implement, just syntax check and pass it to the database, I never mentioned PASSTHRU. |
The above point is not so clear.
You mean ESQL SELECT ORDER BY? There is no ORDER BY in ESQL, you need PASSTHRU to implement one.
The point made by smdavies99 is that to implement ORDER BY in ESQL, you need to use PASSTHRU and that is not used ta many places. |
I don't know of many sites that outlaw 'PASSTHRU'. This becomes a challenge to management to justify the logic of creating a rule:
- You are not allowed to use 'PASSTHRU'
- You are not allowed to use Java.
- You are not allowed to use ESQL.
These are dictates that have little technical merit. 'Just because' is not a good reason. No node or language in WMB is mutually exclusive to the other. Good developers use what they need. If they need PASSTHRU, Java, or ESQL, they should use them. Thats what developing software is all about: making intelligent choices. Laws cannot force under-skilled people to make good choices. _________________ http://leanpub.com/IIB_Tips_and_Tricks
Save $20: Coupon Code: MQSERIES_READER |
|
Back to top |
|
 |
|