This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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 ]
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.
(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
Tony Yan<br /> <br />IBM Certified Developer XML and Related Technology<br />Sun Certified Web Component Developer For J2EE Platform<br />Sun Certified Programmer For Java 2 Platform
Joined: Mar 11, 2002
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)?
Joined: Apr 10, 2002
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,