Altova Mailing List Archives
>xsl-list Archive Home
>Recent entries
>Thread Prev -
>Thread Next - Re: [xsl] cross-reference & xsl:sort - MSXML3 vs MSXML4
[xsl] cross-reference & xsl:sort - MSXML3 vs MSXML4
To:
Date: 4/15/2002 2:39:00 PM
I want to pass in a collection/@name and get a list of all the corresponding part elements (cross refence). Then I want to sort the data first by part/@type, then by part/@name. I lifted the sample xml from a similar note posted to this list in October 2001. That email is duplicated at the bootom. I never did see that problem answered. First, I added a little more sample data (groupC) to the xml: <large-collection> <part id="1" type="type-a" name="name-a"/> <part id="2" type="type-a" name="name-b"/> <part id="3" type="type-b" name="name-c"/> <part id="4" type="type-d" name="name-d"/> <part id="5" type="type-b" name="name-e"/> <part id="6" type="type-c" name="name-f"/> <part id="7" type="type-d" name="name-g"/> <part id="8" type="type-b" name="name-h"/> <part id="9" type="type-c" name="name-i"/> ... <collection name = "groupA"> <ref refid="1"/> <ref refid="3"/> </collection> <collection name = "groupB"> <ref refid="3"/> <ref refid="4"/> </collection> <collection name = "groupC"> <ref refid="1"/> <ref refid="2"/> <ref refid="3"/> <ref refid="4"/> <ref refid="5"/> <ref refid="6"/> <ref refid="7"/> <ref refid="8"/> <ref refid="9"/> </collection> </large-collection> here's my XSL: <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="html" /> <xsl:variable name="MyGroup">groupC</xsl:variable> <xsl:template match="/large-collection/collection"> <xsl:if test="./@name=$MyGroup"> <xsl:for-each select="ref"> <xsl:sort select="/large-collection/part[@id = (current())/@refid]/@type" order="ascending"/> <xsl:sort select="/large-collection/part[@id = (current())/@refid]/@name" order="ascending"/> type: <xsl:value-of select="concat(/large-collection/part[@id = (current())/@refid]/@type, ' name: ', /large-collection/part[@id = (current())/@refid]/@name, ' id: ', /large-collection/part[@id = (current())/@refid]/@id)"/> </xsl:for-each> </xsl:if> </xsl:template> </xsl:stylesheet> I ran this XSLT script using MSXML3 DOM and Processor and got this output: type: type-a name: name-a id: 1 type: type-a name: name-b id: 2 type: type-b name: name-c id: 3 type: type-b name: name-e id: 5 type: type-b name: name-h id: 8 type: type-c name: name-f id: 6 type: type-c name: name-i id: 9 type: type-d name: name-d id: 4 type: type-d name: name-g id: 7 Note the output is sorted correctly (By type, then by name). Now look at the output I get running that same script using MSXML4: type: type-a name: name-a id: 1 type: type-a name: name-b id: 2 type: type-b name: name-c id: 3 type: type-d name: name-d id: 4 type: type-b name: name-e id: 5 type: type-c name: name-f id: 6 type: type-d name: name-g id: 7 type: type-b name: name-h id: 8 type: type-c name: name-i id: 9 This data is in document order! What gives? David >Hi, following is an example of an xml structure that I >require grouped through the use of cross references >based on a parameterised filter value. The xml >structure is fairly large so the use of keys to lookup >the 'part' element is highly desirable. >I am currently using xsl:param to define a filter >value for 'collection@name' having got that I need to >return a result set that for all the 'parts' referred >to by 'ref@refid' references in the 'collection' >grouped by 'part@type', sorted with in each group by >'part@name'. It would also be desirable to have the >result set assigned to an xsl:variable. <large-collection> <part id="1" type="type-a" name="name-a"/> <part id="2" type="type-a" name="name-b"/> <part id="3" type="type-b" name="name-c"/> <part id="4" type="type-d" name="name-d"/> <part id="5" type="type-b" name="name-e"/> <part id="6" type="type-c" name="name-f"/> <part id="7" type="type-d" name="name-g"/> <part id="8" type="type-b" name="name-h"/> <part id="9" type="type-c" name="name-i"/> ... <collection name = "groupA"> <ref refid="1"/> <ref refid="3"/> </collection> <collection name = "groupB"> <ref refid="3"/> <ref refid="4"/> </collection> </large-collection> >Cheers >Tom Hall __________________________________________________ Do You Yahoo!? Yahoo! Tax Center - online filing with TurboTax http://taxes.yahoo.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Disclaimer
These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

