Hi Andy,
I feel a logical sorting solution will be --
For 1st requirement
-------------------
<xsl:template match="/">
<Result>
<xsl:for-each select="Result/Group">
<Group MaterialNumber="{(_at_)MaterialNumber}"
Team="{(_at_)Team}">
<xsl:for-each select="Product">
<xsl:sort select="@ActionCode" />
<Product MaterialNumber="{(_at_)MaterialNumber}"
Team="{(_at_)Team}" Actioncode="{(_at_)ActionCode}">
</Product>
</xsl:for-each>
</Group>
</xsl:for-each>
</Result>
</xsl:template>
For 2nd requirement
-------------------
<xsl:template match="/">
<Result>
<xsl:for-each select="Result/Group">
<xsl:sort select="@MaterialNumber" />
<Group MaterialNumber="{(_at_)MaterialNumber}"
Team="{(_at_)Team}">
<xsl:for-each select="Product">
<xsl:sort select="@MaterialNumber" />
<Product MaterialNumber="{(_at_)MaterialNumber}"
Team="{(_at_)Team}" ActionCode="{(_at_)ActionCode}">
</Product>
</xsl:for-each>
</Group>
</xsl:for-each>
</Result>
</xsl:template>
Its not very clear to me, *how you want to output
<Product> tags which are not within <Group>* . Some
such tags, you are outputting at top and some at
bottom(which does not seem to be a natural sorted
output).
The above XSLs are not producing <Product> tags which
are not within <Group> tags.
I feel, you need to make the _requirement more clear_.
Regards,
Mukul
--- Andy_Freeman(_at_)bd(_dot_)com wrote:
I am trying to sort an XML document by a variety of
different attributes.
Here is an example of the source document:
<Result>
<Product MaterialNumber="494728" Team="ENJ"
ActionCode="C1" />
<Group MaterialNumber="376050" Team="RMT">
<Product MaterialNumber="376050" Team="RMT"
ActionCode="A1" />
<Product MaterialNumber="376009" Team="RMT"
ActionCode="D4" />
</Group>
<Product MaterialNumber="70133" ActionCode="" />
<Group MaterialNumber="75050" Team="RKL">
<Product MaterialNumber="75050" Team="RKL"
ActionCode="J0" />
<Product MaterialNumber="76009" Team="RKL"
ActionCode="A0" />
</Group>
<Product MaterialNumber="70309" Team="DDE"
ActionCode="A5" />
<Group MaterialNumber="75051" Team="RKP">
<Product MaterialNumber="75051" Team="RKP"
ActionCode="J1" />
<Product MaterialNumber="76109" Team="RKP"
ActionCode="A4" />
</Group>
</Result>
I need to sort by the Product ActionCode attribute
at either level to
produce the following output:
<Result>
<Product MaterialNumber="70133" ActionCode="" />
<Group MaterialNumber="75050" Team="RKL">
<Product MaterialNumber="76009" Team="RKL"
ActionCode="A0" />
<Product MaterialNumber="75050" Team="RKL"
ActionCode="J0" />
</Group>
<Group MaterialNumber="376050" Team="RMT">
<Product MaterialNumber="376050" Team="RMT"
ActionCode="A1" />
<Product MaterialNumber="376009" Team="RMT"
ActionCode="D4" />
</Group>
<Group MaterialNumber="75051" Team="RKP">
<Product MaterialNumber="76109" Team="RKP"
ActionCode="A4" />
<Product MaterialNumber="75051" Team="RKP"
ActionCode="J1" />
</Group>
<Product MaterialNumber="70309" Team="DDE"
ActionCode="A5" />
<Product MaterialNumber="494728" Team="ENJ"
ActionCode="C1" />
</Result>
I also need to sort by the Product|Group
MaterialNumber attribute to
produce the following output:
<Result>
<Product MaterialNumber="70133" ActionCode="" />
<Product MaterialNumber="70309" Team="DDE"
ActionCode="A5" />
<Group MaterialNumber="75050" Team="RKL">
<Product MaterialNumber="75050" Team="RKL"
ActionCode="J0" />
<Product MaterialNumber="76009" Team="RKL"
ActionCode="A0" />
</Group>
<Group MaterialNumber="75051" Team="RKP">
<Product MaterialNumber="75051" Team="RKP"
ActionCode="J1" />
<Product MaterialNumber="76109" Team="RKP"
ActionCode="A4" />
</Group>
<Group MaterialNumber="376050" Team="RMT">
<Product MaterialNumber="376009" Team="RMT"
ActionCode="D4" />
<Product MaterialNumber="376050" Team="RMT"
ActionCode="A1" />
</Group>
<Product MaterialNumber="494728" Team="ENJ"
ActionCode="C1" />
</Result>
Note: The example I have shown only has two children
per group. The live
data for this document can have an unlimited number
of children.
TIA,
Andy
**********************************************************************
This message is intended only for the designated
recipient(s). It may
contain confidential or proprietary information and
may be subject to
the attorney-client privilege or other
confidentiality protections.
If you are not a designated recipient, you may not
review, use, copy
or distribute this message. If you receive this in
error, please
notify the sender by reply e-mail and delete this
message. Thank you.
***********************************************************************
XSL-List info and archive:
http://www.mulberrytech.com/xsl/xsl-list
__________________________________
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list