RE: Different stylesheets called on runtime?
Hi Geff, thanks for your help again. I had a day off, so there was no response from me. I still don't get a couple of parts from your answer: /* the class***/ package o2germany.SolutionDelivery.FraudManagement.actions; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; import java.util.Collections; import java.util.HashMap; import java.util.Map; import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.ConfigurationException; import org.apache.avalon.framework.component.ComponentManager; import org.apache.avalon.framework.component.ComponentException; import org.apache.avalon.framework.component.ComponentSelector; import org.apache.avalon.framework.parameters.Parameters; import org.apache.avalon.framework.activity.Disposable; import org.apache.cocoon.environment.Redirector; import org.apache.cocoon.environment.Request; import org.apache.cocoon.environment.SourceResolver; import org.apache.cocoon.environment.ObjectModelHelper; import org.apache.cocoon.acting.ConfigurableComposerAction; import org.apache.avalon.excalibur.datasource.DataSourceComponent; public class StylesheetSelection extends ConfigurableComposerAction implements Disposable { protected ComponentSelector dbselector; DataSourceComponent datasource; public Map act(Redirector redirector, SourceResolver resolver, MapobjectModel, String source, Parameters parameters) throws Exception { HashMap results = new HashMap(); Request request = ObjectModelHelper.getRequest(objectModel); // Get the passed parameters (if there are any) int whichXSL; String report_id = request.getParameter(report_id); String service_id = request.getParameter(service_id); String nbt_pattern_id = request.getParameter(nbt_pattern_id); String search_txt = request.getParameter(search_txt); // Check against a database, bla, bla //e.g whichXSL = 2; ... whichXSL = 2; ... // Now I want to choose the suitable XSL if( whichXSL == 1) // Choose number1.xsl results.put(number1); else if( whichXSL == 2) // Choose number2.xsl results.put(number2); else if( whichXSL == 3) // Choose number3.xsl results.put(number3); else results.put(default); return results; } /*/ But I don't still get where to place these methods (and what they are): /*/ public void compose(ComponentManager manager) throws ComponentException { ... } public void configure(Configuration conf) throws ConfigurationException { ... } public void dispose() { ... } /*/ Where do they belong??? Is the sql-Part in the class or somwhere else? ... String nbt_pattern_id = request.getParameter(nbt_pattern_id); String search_txt = request.getParameter(search_txt); // Check against a database, bla, bla //should the sql be in here ; ... whichXSL = 2; ... I'm asking because you put the sql-part to the end. Cheers Jonny This electronic message contains information from the mmo2 plc Group which may be privileged or confidential. The information is intended to be for the use of the individual(s) or entity named above. If you are not the intended recipient be aware that any disclosure, copying, distribution or use of the contents of this information is prohibited. If you have received this electronic message in error, please notify us by telephone or email (to the numbers or address above) immediately. |-+ | | Geoff Howard | | | cocoon@leveragew| | | eb.com | | || | | 01/23/03 10:24 PM| | | Please respond to| | | cocoon-users | | || |-+ --| | | | To: [EMAIL PROTECTED] | | cc: | | Subject: RE: Different stylesheets called on runtime
Re: Different stylesheets called on runtime?
On 23.Jan.2003 -- 02:36 PM, [EMAIL PROTECTED] wrote: Hi, I have for example an XSP and various XSLs for the output (of the data from that XSP). In the xsp:logic-part it should/is deceided on runtime, which one of the XSLs to use for the output. Where do I have to manage that? I mean, how/where do I tell cocoon which XSL to use(In the sitemap?Can the xsp handle that?)? Yes, the sitemap is the place. No, XSP cannot handle that. You need to use one of the sitemap components for that: a matcher, a selector, or an action. If the stylesheet depends on the request this is pretty easy. If it depends on calculations or data retrieved inside the XSP, you may need to write your own action, selector, matcher. Chris. -- C h r i s t i a n H a u l [EMAIL PROTECTED] fingerprint: 99B0 1D9D 7919 644A 4837 7D73 FEF9 6856 335A 9E08 - Please check that your question has not already been answered in the FAQ before posting. http://xml.apache.org/cocoon/faq/index.html To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Different stylesheets called on runtime?
From: Christian Haul [EMAIL PROTECTED] On 23.Jan.2003 -- 02:36 PM, [EMAIL PROTECTED] wrote: Hi, I have for example an XSP and various XSLs for the output (of the data from that XSP). In the xsp:logic-part it should/is deceided on runtime, which one of the XSLs to use for the output. Where do I have to manage that? I mean, how/where do I tell cocoon which XSL to use(In the sitemap?Can the xsp handle that?)? Yes, the sitemap is the place. No, XSP cannot handle that. You need to use one of the sitemap components for that: a matcher, a selector, or an action. and an input module. If the stylesheet depends on the request this is pretty easy. If it depends on calculations or data retrieved inside the XSP, you may need to write your own action, selector, matcher. input module. Chris, how could you forget about it? ;) -- Konstantin Chris. -- C h r i s t i a n H a u l [EMAIL PROTECTED] fingerprint: 99B0 1D9D 7919 644A 4837 7D73 FEF9 6856 335A 9E08 - Please check that your question has not already been answered in the FAQ before posting. http://xml.apache.org/cocoon/faq/index.html To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - Please check that your question has not already been answered in the FAQ before posting. http://xml.apache.org/cocoon/faq/index.html To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Different stylesheets called on runtime?
On 23.Jan.2003 -- 05:57 PM, Konstantin Piroumian wrote: From: Christian Haul [EMAIL PROTECTED] On 23.Jan.2003 -- 02:36 PM, [EMAIL PROTECTED] wrote: input module. Chris, how could you forget about it? ;) Dear me! But it looks like I successfully missionated so far ;-) Cheers. Chris. -- C h r i s t i a n H a u l [EMAIL PROTECTED] fingerprint: 99B0 1D9D 7919 644A 4837 7D73 FEF9 6856 335A 9E08 - Please check that your question has not already been answered in the FAQ before posting. http://xml.apache.org/cocoon/faq/index.html To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Different stylesheets called on runtime?
-Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] Sent: Thursday, January 23, 2003 9:47 AM To: [EMAIL PROTECTED] Subject: Re: Different stylesheets called on runtime? Thanks for the quick and helpfull response. Thats the answer I kind of expected and feared most. That means for me: Getting comfortable with actions. Well, the good news is that in my opinion (and experience) actions are about as easy as it gets when extending cocoon. There's only one method to implement, and the only contract you need to code for is to return null if the action fails and return a Map of the key-value pairs you need to reference in the sitemap if the action is successful. (or any empty map if you don't need to reference values in the sitemap). Ask some specific questions here about what problems you have getting started. Geoff Howard Cheers Jonny - Please check that your question has not already been answered in the FAQ before posting. http://xml.apache.org/cocoon/faq/index.html To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Different stylesheets called on runtime?
Hi Geff, thanks for your help. Ok. Example: _ My XSP, that should choose which XSL to use.: ?xml version=1.0 encoding=ISO-8859-1? xsp:page language=java xmlns:xsp=http://apache.org/xsp; xmlns:xsp-request=http://apache.org/xsp/request/2.0; xsp:structure xsp:includejava.sql.*/xsp:include^ /xsp:structure results !-- Get the passed parameters (if there are any) -- xsp:logic int whichXSL; String report_id = request.getParameter(report_id); String service_id = request.getParameter(service_id); String nbt_pattern_id = request.getParameter(nbt_pattern_id); String search_txt = request.getParameter(search_txt); ... // Check against a database, bla, bla ... // Now I want to choose the suitable XSL if( whichXSL == 1) // Choose number1.xsl else if( whichXSL == 2) // Choose number2.xsl else if( whichXSL == 3) // Choose number3.xsl ... // data data ... ... Part of sitemap: ... map:match pattern=differentXSLs map:generate type=serverpages src=differentXSLs.xsp/ !-- if whichXSL == 1 -- !-- map:transform src=number1.xsl/-- !-- if whichXSL == 2 -- !-- map:transform src=number2.xsl/-- !-- if whichXSL == 3 -- !-- map:transform src=number3.xsl/-- ... map:serialize/ /map:match So how and where should I place my action (and how should it look like)? How should my xsp look like then? How should my xsl look like then? Cheers Jonny This electronic message contains information from the mmo2 plc Group which may be privileged or confidential. The information is intended to be for the use of the individual(s) or entity named above. If you are not the intended recipient be aware that any disclosure, copying, distribution or use of the contents of this information is prohibited. If you have received this electronic message in error, please notify us by telephone or email (to the numbers or address above) immediately. |-+ | | Geoff Howard | | | cocoon@leveragew| | | eb.com | | || | | 01/23/03 04:27 PM| | | Please respond to| | | cocoon-users | | || |-+ --| | | | To: [EMAIL PROTECTED] | | cc: | | Subject: RE: Different stylesheets called on runtime? | --| -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] Sent: Thursday, January 23, 2003 9:47 AM To: [EMAIL PROTECTED] Subject: Re: Different stylesheets called on runtime? Thanks for the quick and helpfull response. Thats the answer I kind of expected and feared most. That means for me: Getting comfortable with actions. Well, the good news is that in my opinion (and experience) actions are about as easy as it gets when extending cocoon. There's only one method to implement, and the only contract you need to code for is to return null if the action fails and return a Map of the key-value pairs you need to reference in the sitemap if the action is successful. (or any empty map if you don't need to reference values in the sitemap). Ask some specific questions here about what problems you have getting started. Geoff Howard Cheers Jonny - Please check that your question has not already been answered in the FAQ before posting. http://xml.apache.org/cocoon/faq/index.html To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - Please check that your question has not already been answered in the FAQ before posting. http://xml.apache.org/cocoon/faq/index.html To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL
Re: Different stylesheets called on runtime?
On 23.Jan.2003 -- 05:42 PM, [EMAIL PROTECTED] wrote: int whichXSL; String report_id = request.getParameter(report_id); String service_id = request.getParameter(service_id); String nbt_pattern_id = request.getParameter(nbt_pattern_id); String search_txt = request.getParameter(search_txt); ... // Check against a database, bla, bla ... // Now I want to choose the suitable XSL if( whichXSL == 1) Unfortunately, you've skipped the crucial part i.e. how the xsl is chosen :-| ... map:match pattern=differentXSLs map:generate type=serverpages src=differentXSLs.xsp/ !-- if whichXSL == 1 -- !-- map:transform src=number1.xsl/-- !-- if whichXSL == 2 -- !-- map:transform src=number2.xsl/-- !-- if whichXSL == 3 -- !-- map:transform src=number3.xsl/-- ... map:serialize/ /map:match So how and where should I place my action (and how should it look like)? around one transform and use a returned value as file name, e.g. map:act type=sel-style map:transform src={file}.xsl/ /map How should my xsp look like then? rip out everything related to the XSL How should my xsl look like then? no change. Chris. -- C h r i s t i a n H a u l [EMAIL PROTECTED] fingerprint: 99B0 1D9D 7919 644A 4837 7D73 FEF9 6856 335A 9E08 - Please check that your question has not already been answered in the FAQ before posting. http://xml.apache.org/cocoon/faq/index.html To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Different stylesheets called on runtime?
Unfortunately, you've skipped the crucial part i.e. how the xsl is chosen :-| I think I don't understand you right., but this should be just an dummy example. So if(whichXSL == 1) then the number1.xsl should be choosen for output, else if(whichXSL == 2) then the number2.xsl should be choosen for output, bla, bla. I hope this is clearer. around one transform and use a returned value as file name, e.g. map:act type=sel-style map:transform src={file}.xsl/ /map Ok. But I don't get the part (in combination with the xsp) how, if for example number2.xsl is choosen, to choose it. How do I produce the return value in the xsp? How should my xsl look like then? no change. Copypaste mistake. Thanks Jonny This electronic message contains information from the mmo2 plc Group which may be privileged or confidential. The information is intended to be for the use of the individual(s) or entity named above. If you are not the intended recipient be aware that any disclosure, copying, distribution or use of the contents of this information is prohibited. If you have received this electronic message in error, please notify us by telephone or email (to the numbers or address above) immediately. |-+-- | | Christian Haul | | | [EMAIL PROTECTED]| | | rmstadt.de| | | | | | 01/23/03 06:14 PM | | | Please respond to | | | cocoon-users | | | | |-+-- --| | | | To: [EMAIL PROTECTED] | | cc: | | Subject: Re: Different stylesheets called on runtime? | --| On 23.Jan.2003 -- 05:42 PM, [EMAIL PROTECTED] wrote: int whichXSL; String report_id = request.getParameter(report_id); String service_id = request.getParameter(service_id); String nbt_pattern_id = request.getParameter(nbt_pattern_id); String search_txt = request.getParameter(search_txt); ... // Check against a database, bla, bla ... // Now I want to choose the suitable XSL if( whichXSL == 1) Unfortunately, you've skipped the crucial part i.e. how the xsl is chosen :-| ... map:match pattern=differentXSLs map:generate type=serverpages src=differentXSLs.xsp/ !-- if whichXSL == 1 -- !-- map:transform src=number1.xsl/-- !-- if whichXSL == 2 -- !-- map:transform src=number2.xsl/-- !-- if whichXSL == 3 -- !-- map:transform src=number3.xsl/-- ... map:serialize/ /map:match So how and where should I place my action (and how should it look like)? around one transform and use a returned value as file name, e.g. map:act type=sel-style map:transform src={file}.xsl/ /map How should my xsp look like then? rip out everything related to the XSL How should my xsl look like then? no change. Chris. -- C h r i s t i a n H a u l [EMAIL PROTECTED] fingerprint: 99B0 1D9D 7919 644A 4837 7D73 FEF9 6856 335A 9E08 - Please check that your question has not already been answered in the FAQ before posting. http://xml.apache.org/cocoon/faq/index.html To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - Please check that your question has not already been answered in the FAQ before posting. http://xml.apache.org/cocoon/faq/index.html To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Different stylesheets called on runtime?
On 23.Jan.2003 -- 06:35 PM, [EMAIL PROTECTED] wrote: Unfortunately, you've skipped the crucial part i.e. how the xsl is chosen :-| I think I don't understand you right., but this should be just an dummy example. So if(whichXSL == 1) then the number1.xsl should be choosen for output, else if(whichXSL == 2) then the number2.xsl should be choosen for output, bla, bla. I hope this is clearer. You cannot change the transformation with data from the XSP. Period. Before you reach that part of the XSP, the pipeline has been setup and the transformation has already begun. If you told us how the style is chosen, we might have been able to point you to some existing components to use instead. around one transform and use a returned value as file name, e.g. map:act type=sel-style map:transform src={file}.xsl/ /map Ok. But I don't get the part (in combination with the xsp) how, if for example number2.xsl is choosen, to choose it. How do I produce the return value in the xsp? You don't. It's impossible. (sort of) Chris. -- C h r i s t i a n H a u l [EMAIL PROTECTED] fingerprint: 99B0 1D9D 7919 644A 4837 7D73 FEF9 6856 335A 9E08 - Please check that your question has not already been answered in the FAQ before posting. http://xml.apache.org/cocoon/faq/index.html To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Different stylesheets called on runtime?
OK, now I have to think of an other way, how to choose my XSLs. or The different XSLs are choosen from request parameters and an resulting database query. Is there a way to do that in an action or somewhere else? Cheers Jonny This electronic message contains information from the mmo2 plc Group which may be privileged or confidential. The information is intended to be for the use of the individual(s) or entity named above. If you are not the intended recipient be aware that any disclosure, copying, distribution or use of the contents of this information is prohibited. If you have received this electronic message in error, please notify us by telephone or email (to the numbers or address above) immediately. |-+-- | | Christian Haul | | | [EMAIL PROTECTED]| | | rmstadt.de| | | | | | 01/23/03 06:51 PM | | | Please respond to | | | cocoon-users | | | | |-+-- --| | | | To: [EMAIL PROTECTED] | | cc: | | Subject: Re: Different stylesheets called on runtime? | --| On 23.Jan.2003 -- 06:35 PM, [EMAIL PROTECTED] wrote: Unfortunately, you've skipped the crucial part i.e. how the xsl is chosen :-| I think I don't understand you right., but this should be just an dummy example. So if(whichXSL == 1) then the number1.xsl should be choosen for output, else if(whichXSL == 2) then the number2.xsl should be choosen for output, bla, bla. I hope this is clearer. You cannot change the transformation with data from the XSP. Period. Before you reach that part of the XSP, the pipeline has been setup and the transformation has already begun. If you told us how the style is chosen, we might have been able to point you to some existing components to use instead. around one transform and use a returned value as file name, e.g. map:act type=sel-style map:transform src={file}.xsl/ /map Ok. But I don't get the part (in combination with the xsp) how, if for example number2.xsl is choosen, to choose it. How do I produce the return value in the xsp? You don't. It's impossible. (sort of) Chris. -- C h r i s t i a n H a u l [EMAIL PROTECTED] fingerprint: 99B0 1D9D 7919 644A 4837 7D73 FEF9 6856 335A 9E08 - Please check that your question has not already been answered in the FAQ before posting. http://xml.apache.org/cocoon/faq/index.html To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - Please check that your question has not already been answered in the FAQ before posting. http://xml.apache.org/cocoon/faq/index.html To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Different stylesheets called on runtime?
yes, absolutely - an action can do that. The easiest way (IMO) is to just code the java, although they apparently can be written in xsp. I'd get the concept first in java, though and then try doing it in xsp if you want. I'll mark up your original email with some examples of how it would be done. Sorry I dropped out there for a while - i'm working from home on one phone line and have been expecting some important calls so trying to stay offline when not necessary. Geoff -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] Sent: Thursday, January 23, 2003 12:59 PM To: [EMAIL PROTECTED] Subject: Re: Different stylesheets called on runtime? OK, now I have to think of an other way, how to choose my XSLs. or The different XSLs are choosen from request parameters and an resulting database query. Is there a way to do that in an action or somewhere else? Cheers Jonny -- -- This electronic message contains information from the mmo2 plc Group which may be privileged or confidential. The information is intended to be for the use of the individual(s) or entity named above. If you are not the intended recipient be aware that any disclosure, copying, distribution or use of the contents of this information is prohibited. If you have received this electronic message in error, please notify us by telephone or email (to the numbers or address above) immediately. |-+-- | | Christian Haul | | | [EMAIL PROTECTED]| | | rmstadt.de| | | | | | 01/23/03 06:51 PM | | | Please respond to | | | cocoon-users | | | | |-+-- - -| | | | To: [EMAIL PROTECTED] | | cc: | | Subject: Re: Different stylesheets called on runtime? | - -| On 23.Jan.2003 -- 06:35 PM, [EMAIL PROTECTED] wrote: Unfortunately, you've skipped the crucial part i.e. how the xsl is chosen :-| I think I don't understand you right., but this should be just an dummy example. So if(whichXSL == 1) then the number1.xsl should be choosen for output, else if(whichXSL == 2) then the number2.xsl should be choosen for output, bla, bla. I hope this is clearer. You cannot change the transformation with data from the XSP. Period. Before you reach that part of the XSP, the pipeline has been setup and the transformation has already begun. If you told us how the style is chosen, we might have been able to point you to some existing components to use instead. around one transform and use a returned value as file name, e.g. map:act type=sel-style map:transform src={file}.xsl/ /map Ok. But I don't get the part (in combination with the xsp) how, if for example number2.xsl is choosen, to choose it. How do I produce the return value in the xsp? You don't. It's impossible. (sort of) Chris. -- C h r i s t i a n H a u l [EMAIL PROTECTED] fingerprint: 99B0 1D9D 7919 644A 4837 7D73 FEF9 6856 335A 9E08 - Please check that your question has not already been answered in the FAQ before posting. http://xml.apache.org/cocoon/faq/index.html To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - Please check that your question has not already been answered in the FAQ before posting. http://xml.apache.org/cocoon/faq/index.html To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - Please check that your question has not already been answered in the FAQ before posting. http://xml.apache.org/cocoon/faq/index.html To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Different stylesheets called on runtime?
-Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] Sent: Thursday, January 23, 2003 11:42 AM To: [EMAIL PROTECTED] Subject: RE: Different stylesheets called on runtime? Hi Geff, thanks for your help. Ok. Sure. Ok, Example: _ My XSP, that should choose which XSL to use.: As an xsp is usually used to create a generator, you don't want to use it to select anything about pipeline behavior. You can write actions in xsp, but for now that will probably confuse things. So, you'll take the logic from the xsp you had, and reuse it in an action. Before getting into that, though look at the sitemap. I think Christian already gave you your answer there but again, you'll want to do something like this: Part of sitemap: ... map:match pattern=differentXSLs !-- you'll now need to strip out the transformer selection logic from the xsp and just generate the xml that your xsl needs -- map:generate type=serverpages src=differentXSLs.xsp/ map:act type=myAction map:transform src={whichXSL}.xsl/ ... map:serialize/ /map:act !-- normally you'd put fall back behavior here - executed only when the action fails. For the example though we'll just make the action always succeed. You may want to change things around - putting everything inside the action tag, putting only the transform in the action tag. For the example it doesn't matter though. -- /map:match So how and where should I place my action (and how should it look like)? If you mean the compiled action, it goes in WEB-INF/classes or inside a jar in WEB-INF/lib How should my xsl look like then? this shouldn't have to change. Now the java action. this is more complicated than I originally indicated because of the database access, but it's still not that bad. I simplified a few things, but resisted the urge to dumb it down. For instance, you could hard code the datasource name and get rid of configure(). You could skip dispose() but I think that would lead to memory problems. (avalon gurus - is that right?) I have combined this quickly from a DB Action super class I have and one subclass. When this is compiled, it gets defined in the map:components section of the sitemap: map:actions map:act name=myAction src=you.yourcompany.acting.YourAction logger=sitemap.whateveryouwant/ package you.yourcompany.acting; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; import java.util.Collections; import java.util.HashMap; import java.util.Map; import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.ConfigurationException; import org.apache.avalon.framework.component.ComponentManager; import org.apache.avalon.framework.component.ComponentException; import org.apache.avalon.framework.component.ComponentSelector; import org.apache.avalon.framework.parameters.Parameters; import org.apache.avalon.framework.activity.Disposable; import org.apache.cocoon.environment.Redirector; import org.apache.cocoon.environment.Request; import org.apache.cocoon.environment.SourceResolver; import org.apache.cocoon.environment.ObjectModelHelper; import org.apache.cocoon.acting.ConfigurableComposerAction; import org.apache.avalon.excalibur.datasource.DataSourceComponent; public class YourAction extends ConfigurableComposerAction implements Disposable { protected ComponentSelector dbselector; DataSourceComponent datasource; public Map act(Redirector redirector, SourceResolver resolver, Map objectModel, String source, Parameters parameters) throws Exception { HashMap results = new HashMap(); Request request = ObjectModelHelper.getRequest(objectModel); !-- Get the passed parameters (if there are any) -- int whichXSL; String report_id = request.getParameter(report_id); String service_id = request.getParameter(service_id); String nbt_pattern_id = request.getParameter(nbt_pattern_id); String search_txt = request.getParameter(search_txt); ... // Check against a database, bla, bla ... // Now I want to choose the suitable XSL if( whichXSL == 1) // Choose number1.xsl results.put(number1); else if( whichXSL == 2) // Choose number2.xsl results.put(number2); else if( whichXSL == 3) // Choose number3.xsl results.put(number3); else { results.put(default); // not strictly necessary // could also return null to signal sitemap to execute fallback. up to you. } ... return results; } // end of act() // Now, you glossed over the database stuff but there's a few methods you'll need to // handle that. They will be called by cocoon during the normal component lifecycle // and are designed
Re: Different stylesheets called on runtime?
[EMAIL PROTECTED] wrote: My XSP, that should choose which XSL to use.: Another possibility is to use *one* style sheet containing all the templates and match on the document element to choose the processing path. For example, you want to use 2 style sheets: 1.xsl xsl:stylesheet ... xsl:template match=foo ... /xsl:stylesheet 2.xsl xsl:stylesheet ... xsl:template match=bar ... /xsl:stylesheet First, add a mode to all templates to avoid name clashes, and perhaps prefixes to global variables and parameters: 1.xsl xsl:stylesheet ... xsl:template match=foo mode=xsl1 ... /xsl:stylesheet 2.xsl xsl:stylesheet ... xsl:template match=bar mode=xsl2 ... /xsl:stylesheet Make a stylesheet including all of the above and a document element matching template to choose the further processing path: all.xsl: xsl:stylesheet ... xsl:include href=1.xsl/ xsl:include href=2.xsl/ xsl:template match=/xsl1 xsl:apply-templates mode=xsl1/ /xsl:template xsl:template match=/xsl2 xsl:apply-templates mode=xsl2/ /xsl:template /xsl:stylesheet Your XSP has simply to provide the appropriate document element. I have absolutely no experience with XSP so I have to guess... xsp:page language=java... !-- Get the passed parameters (if there are any) -- xsp:logic int whichXSL; ... // Now I want to choose the suitable XSL if( whichXSL == 1) /xsp:logic xsl1 results logic to put data here /results /xsl1 xsp:logic else if( whichXSL == 2) /xsp:logic xsl2 results logic to put data here /results /xsl2 xsp:logic ... You'll have to rearrange your data generation a bit, of course. If you don't want to do this, use a marker element xsp:page language=java... !-- Get the passed parameters (if there are any) -- results xsp:logic int whichXSL; ... // Now I want to choose the suitable XSL if( whichXSL == 1) /xsp:logic xsl1/ xsp:logic else if( whichXSL == 2) /xsp:logic xsl2/ xsp:logic and in the XSL xsl:template match=/ xsl:apply-templates select=/results/*[1]/ /xsl:template xsl:template match=/results/xsl1 xsl:apply-templates mode=xsl1/ /xsl:template xsl:template match=/results/xsl2 xsl:apply-templates mode=xsl2/ /xsl:template The marker element must be the first child ot the results element. There are ways to get around this, for example using namespaces and matching xsl:apply-templates select=/results/*[namespace-uri()='uri:foo']/ HTH J.Pietschmann - Please check that your question has not already been answered in the FAQ before posting. http://xml.apache.org/cocoon/faq/index.html To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]