SunQuest
           XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old December 8th, 2002, 02:31 PM
delsweil delsweil is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Posts: 5 delsweil User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
dynamic use of XSLT to implement search function

Hi,

Is it possible to use XSLT in the following context?

I would like to search XML file and display information on the returned nodes.

This is best illustrated by example:

<library>
<book>
<title>a first book</title>
<author>a first author</author>
</book>
<book>
<title>a second book</title>
<author>a second author</author>
</book>
<book>
<title>a second book</title>
<author>a first author</author>
</book>
</library>

I would like to offer a search facility in an html page, that will for example traverse the tree and output the details for a specific author. Could this be achieved by passing in an XPath expression as a parameter? Any other suggestions would be most welcome.

Thanks for any help,

Dave

Reply With Quote
  #2  
Old December 8th, 2002, 06:47 PM
a.koepke's Avatar
a.koepke a.koepke is offline
Second highest poster :p
Dev Shed God 5th Plane (7000 - 7499 posts)
 
Join Date: Jul 2001
Posts: 7,323 a.koepke User rank is Sergeant (500 - 2000 Reputation Level)a.koepke User rank is Sergeant (500 - 2000 Reputation Level)a.koepke User rank is Sergeant (500 - 2000 Reputation Level)a.koepke User rank is Sergeant (500 - 2000 Reputation Level)a.koepke User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 8 h 8 m 45 sec
Reputation Power: 27
I have been working on a cd based project doing exactly this for the past 2 weeks. I created a function called show that gets passed the xml & xsl files. In this case i actually modified the xslt_process function to use a value from the arguements variable ('arg:/_xsl')

PHP Code:
function show($xmlFile,$xslFile$arguments
 {
  
$xh xslt_create();
  
$result xslt_process($xh$xmlFile'arg:/_xsl'NULL$arguments);
  print 
$result;
  
xslt_free($xh);
 } 


What i did is use file & join to load file and then the assign to arguements after doing an strreplace on file

PHP Code:
 $xsl=join("",file("bol.xsl"));/[php]

[
php]$arguments = array('/_xsl' => $xsl ); 


In the XSL file i had key words/variables which I replaced with the xsl search tags then. Once all that was done i ran the show function.

PHP Code:
 show("webpages/bol.xml","",$arguments); 


If any of this doesnt make sense please let me know and i will try and explain it better.

Reply With Quote
  #3  
Old December 9th, 2002, 04:31 AM
delsweil delsweil is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Posts: 5 delsweil User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hi Andreas,

Firstly thank you for you quick reply. I'm not sure I completely understand what you have achieved, however, I think I get the basic idea. Is this correct? You are changing the XSLT templates on the fly via PHP file handling? I have no experience of PHP and it's not really suitable for my purpose but as I am working with local based files, I think I could implement something similar in JavaScript.

Do you have a working prototype or demo that I could see? Or even an example XSLT file?

Your help is really appreciated,

Dave

Reply With Quote
  #4  
Old December 9th, 2002, 05:26 AM
a.koepke's Avatar
a.koepke a.koepke is offline
Second highest poster :p
Dev Shed God 5th Plane (7000 - 7499 posts)
 
Join Date: Jul 2001
Posts: 7,323 a.koepke User rank is Sergeant (500 - 2000 Reputation Level)a.koepke User rank is Sergeant (500 - 2000 Reputation Level)a.koepke User rank is Sergeant (500 - 2000 Reputation Level)a.koepke User rank is Sergeant (500 - 2000 Reputation Level)a.koepke User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 8 h 8 m 45 sec
Reputation Power: 27
Thats right... i am loading the basic XSL and then changing it as needed. I am not sure how you would achieve the same result via javascript. You might be able to do it via XSL variables but i dont know for sure.

Reply With Quote
  #5  
Old December 9th, 2002, 03:49 PM
delsweil delsweil is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Posts: 5 delsweil User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
thanks again Andreas,

I will look into the methods you suggested.

Could you show me a sample XSLT template or just the XPath expression that searches on a cd title for example?

That would be of great use.

Thanks again,

Dave

Reply With Quote
  #6  
Old December 9th, 2002, 06:13 PM
a.koepke's Avatar
a.koepke a.koepke is offline
Second highest poster :p
Dev Shed God 5th Plane (7000 - 7499 posts)
 
Join Date: Jul 2001
Posts: 7,323 a.koepke User rank is Sergeant (500 - 2000 Reputation Level)a.koepke User rank is Sergeant (500 - 2000 Reputation Level)a.koepke User rank is Sergeant (500 - 2000 Reputation Level)a.koepke User rank is Sergeant (500 - 2000 Reputation Level)a.koepke User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 8 h 8 m 45 sec
Reputation Power: 27
I use the <xsl:for-each> tag and then just pass an extra option to it. <xsl:for-each select="People[FirstName='Mary']">

This would display all people that have the first name of Mary. If you want to learn XSL i would suggest the XSL tutorials from Devshed. I only learnt XSL a week ago and found everything by searching the web. There is heaps of tutorials out there


http://www.devshed.com/Server_Side/...sics/XSLBasics1

http://www.devshed.com/Server_Side/...sics/XSLBasics2

Reply With Quote
  #7  
Old December 19th, 2002, 12:08 PM
delsweil delsweil is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Posts: 5 delsweil User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hi Andreas,

Sorry for the delay in thanking you, I thought I had posted a reply but obviously forgot.

Just to let you know that I found, what I think is a more elegant solution to the problem.

It involves using JavaScript to query the xml file using XPath expressions.

The code below queries the XML file on artist and returns all of a NodeList of all the Al Green Tracks.

The data is then outputted to a table.

<SCRIPT LANGUAGE="JavaScript">
<!--

var xmlDoc = new ActiveXObject("Msxml2.DOMDocument");
xmlDoc.async = false;
xmlDoc.load("sample.xml");
//xmlDoc.setProperty("SelectionLanguage", "XPath");


function ex1(query) {
var matchedNodes = xmlDoc.childNodes[1].selectNodes(query);
document.writeln("<table border='1'>");
for (var i=0; i< matchedNodes.length; i++) {
document.writeln("<tr>");
for (var j=0; j< matchedNodes[i].childNodes.length; j++) {
document.writeln("<td>"+matchedNodes[i].childNodes[j].text+"</td>");
if (j == matchedNodes.length -1)
document.writeln("</tr>");
}
}
document.writeln("</table>");
}

var query = "track[artist='Al Green']";

ex1(query);
// -->
</SCRIPT>

This may be of use to you in the future.

Regards,

Dave

Reply With Quote
  #8  
Old December 19th, 2002, 09:47 PM
a.koepke's Avatar
a.koepke a.koepke is offline
Second highest poster :p
Dev Shed God 5th Plane (7000 - 7499 posts)
 
Join Date: Jul 2001
Posts: 7,323 a.koepke User rank is Sergeant (500 - 2000 Reputation Level)a.koepke User rank is Sergeant (500 - 2000 Reputation Level)a.koepke User rank is Sergeant (500 - 2000 Reputation Level)a.koepke User rank is Sergeant (500 - 2000 Reputation Level)a.koepke User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 8 h 8 m 45 sec
Reputation Power: 27
When i was doing my research i did see that solution you posted. The one main problem with it is that it will only work in internet explorer since it uses ActiveX. Also you need to ensure that your browser is of the right version to. In a web based situation this is not possible and therefore that system is useless. Thats why its better doing it server sided.

If its for an intranet situation or a controlled environment then the solution will be fine.

Reply With Quote
  #9  
Old December 20th, 2002, 02:35 AM
delsweil delsweil is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Posts: 5 delsweil User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
yeah, I'm using it in a "non-web" based application. Although a cross-browser implementation would be nice, it is not a priority in my situation.

best,

Dave

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > dynamic use of XSLT to implement search function


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway