• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Using XSL to filter XML & Multiple XSLs

 
Ranch Hand
Posts: 1140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Two questions here
Q1: Is it possible to get a subset of data from a XML file using XSL alone?
Example: If I have a XML template like the one given below

Say when I open the XML file in a browser, that XSL should make sure that only a subset of data (say where SEX=M or where AGE > 20) will be displayed. Possible?
Q2: I have 1 XML file and 2 XSL file. I want the XML file to use the first XSL at times and the second XSL file at other times. It should happen dynamically. How to do it?
Restrictions
-I can't use Server side processing (Servlets / JSP / ASP...)
-I can't modify the XML file (or atleast, I dont want to modify it)
[ October 23, 2003: Message edited by: Mani Ram ]
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Q1: Is it possible to get a subset of data from a XML file using XSL alone?

Yes, that's entirely possible. The output of an XSL transformation intended for visualizing the data rarely preserves all information.

Q2: I have 1 XML file and 2 XSL file. I want the XML file to use the first XSL at times and the second XSL file at other times. It should happen dynamically. How to do it?
Restrictions
-I can't use Server side processing (Servlets / JSP / ASP...)
-I can't modify the XML file (or atleast, I dont want to modify it)

The only way I can think of is to make the first XSL (referred to by the original XML file) generate another XML document, which in turn refers to the second XSL stylesheet. However, I really don't know whether the browsers support this kind of double-transformation.
 
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
(q1) There are many ways, (a) xsl:key (b) xml query (c) brutal force, for-each looping and checking (d) ...?
(q2) When you say at times and other times, what do you mean? where is this information/criteria for determing which xsl to use? If it exists in the XML as a value, then you can use one XSL and then choose the style depending on that value inside that XSL. If it is outside of the XML, then your app should know which xsl to use. If you need random selection, your app should decide it, not XML or XSL.
my 2 cents
 
Mani Ram
Ranch Hand
Posts: 1140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the suggestions.
Here is my actual problem. There is a XML file like the one given below (currently it doesn;t have any XSL associted).

Now, I have to build a HTML page with an option for the user to select the country he wants to view. When he submits the form, I have to display this XML, but only containing the data which matches the country entered by the user. (If he selects India as the country, only the first and the fifth set of the above data should be displayed).
How to do this (with out using any server side tasks)?
 
Tony Yan
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try something like:
<xsl:copy-of select="//CITY[COUNTRY='India']"/>
Where //CITY picks up all the CITY nodes and content in [] leaves only COUNTRY equals to 'India' nodes. Copy-of should dump everything from CITY Downward.
Regards,
 
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You don't need two or more xslt files. You can use parameter to pass country user selected to the xslt to solve your problem.
 
reply
    Bookmark Topic Watch Topic
  • New Topic