Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 3rd, 2005, 03:26 PM
Registered User
 
Join Date: Sep 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default Newbie help- filtering one XML file with another

I need to merge, sort, and filter records from a master XML file based on data in another XML document (one of many). I want to capture the entire contents of a "header" section, and all node information that match by category. While this isn't the real situation, I think the Top seller by category Book example will illustrate.

Suppose I want to generate an XML file that list top seller books by category, based on the interests of each subscriber. That file will have a common greeting, and all the details for only the categories of Books the subscriber is interested in, sorted by their ranking. We have a master XML file that is structured something like this:

<Greeting>... stuff... </Greeting>
<Top Sellers>
<Top Seller>
<category>Art</category>
<Title>...</Title>
</Top Seller>
<Top Seller>
<category>Suspense</category>
<Title>...</Title>
</Top Seller>
<Top Seller>
<category>Chemical Engineering</category>
<Title>...</Title>
</Top Seller>
<Top Seller>
<category>Drama</category>
<Title>...</Title>
</Top Seller>
</Top Sellers>


Then, there is a subscriber specific file that looks something like this:


<USERPREFS>
<preference>
<Category>Suspense</Category>
<Rank>1</Rank>
</preference>
<preference>
<Category>Sports</Category>
<Rank>2</Rank>
</preference>
<preference>
<Category>Humor</Category>
<Rank>3</Rank>
</preference>
<preference>
</preference>
</USERPREFS>


The result I'm wanting to have is something like this

<Greeting>... stuff... </Greeting>
<Top Sellers>
<Top Seller>
<category>Suspense</category>
<Title>...<Title>
</Top Seller>
<Top Seller>
<category>Sorts</category>
<Title>...<Title>
</Top Seller>
<Top Seller>
<category>Humor</category>
<Title>...<Title>
</Top Seller>
</Top Sellers>

where the contents of the greeting node contains all the details in the first file, ranked based on the second, and the content of all the matching top sellers nodes is also in the result file.

There will be many different "preference files" that will be applied to the same XML "master", so hard-coding the file name in an XSLT doesn't seem to be an option.

Seems like I might need to transform the second XML file into an intermediate XSLT, then apply that one to the first file. If this is the best approach, I'm having a hard time visualizing what the intermediate XSLT should look like (thus far, my XSLT experience is limited to relatively simple "for each" type transforms).

A code snippet or link to another topic that has a working example would be greatly appreciated.
 
Old September 6th, 2005, 04:52 PM
Registered User
 
Join Date: Sep 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have found a way to address this issue- transforming the two files into a single file first using one XSLT, then looking for following-siblings in a second one. Sorting the result has not been addressed, is less critical and should be fairly easy.

I do have one new, related question-

The first XSLT involves a parameter (the second file name). If anyone has a working example of how msxml2 can be sent XSLT paramters from VB6, that would be appreciated. Sources I've found on the web thus far are from a pre-release version of MSXML and don't work with current code.. Not a show stopper. If I need to I can shell out to MSXSL.exe and pass the paramter there.
 
Old September 7th, 2005, 02:12 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

The sdk for version 4 is available by going to msdn.com/xml and hunting on the first page.
There are two methods of passing a parameter, the official way and the hackers' way.

Official way: use the addParameter method:
http://msdn.microsoft.com/library/de...68e8c032b7.asp

Hackers' way: Open the XSLT in a domdocument. Assign the namespace prefix "xsl" to the standard URI using "setProperty" and "SelectionNamespaces" (See sdk if you are unfamiliar with this. Search for your parameter element, selectSingleNode("xsl:param[@name = 'myParamName']"). Modify select attribute or text value depending on how you set up the param.



--

Joe (Microsoft MVP - XML)
 
Old September 7th, 2005, 08:15 AM
Registered User
 
Join Date: Sep 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks, that works great...





Similar Threads
Thread Thread Starter Forum Replies Last Post
Filtering XML data aldwinenriquez XSLT 7 August 25th, 2008 03:24 AM
XML Filtering BlkR XML 1 June 12th, 2008 05:25 PM
Help with filtering xml jconroy XSLT 6 April 6th, 2008 11:33 PM
filtering xml in using XSLT venjamin XSLT 1 October 20th, 2006 04:21 AM
Filtering XML data based on differnt XML ahmed123 XSLT 5 August 11th, 2006 09:15 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.