This command should be on a single line. Notice that for the Oracle parser, we had to put single quotes around the text value magenta. Notice that we used the setParameter method to set global parameters for the Transformer object before we invoke the transform method.
This transformation generates the following results in output. Skip to main content. XSLT by. Start your free trial. Defining a Parameter in a Template. This browser is no longer supported.
Download Microsoft Edge More info. Contents Exit focus mode. Is this page helpful? Please rate your experience Yes No. Any additional feedback? Submit and view feedback for This product This page. It is. Update: In response to the answers I initially received, which pointed out that the example I made up was not completely correct my mistake and did not very clearly show the issue ie: that the correct template is being called, but that only the parameter appears to not be working , I have replaced the examples with much better ones.
This example more clearly shows that the testNode template is successfully being called, but that the parameter does not seem to be passed.
I have tested this numerous times, before and after consideration of the previous answers to this question. I am absolutely stumped, as everything appears to be correct from what I have read elsewhere and what people have suggested so far. In XSLT 2. Another way is to have global parameters , so that they wouldn't have to be passed through every template in the chain. The reason is in the code you haven't shown to us.
Or maybe the source XML document you have in your real case isn't the same as the one provided here. I ran the provided code and I couldn't repro the problem at all -- the desired output is produced. My guess is that some other template is selected before the template that matches testNode. This template doesn't know anything about the passed parameter and it doesn't pass it to the templates that it, on its turn, applies. Thus the parameter is not passed at all to the template matching testNode.
Also, you could trace with an XSLT debugger such as the one in Visual Studio and see exactly which template is selected. As I said earlier, global parameters can be used as alternative -- I am not sure that this is better, though. Now it is obvious that the problem is caused by allowing the XSLT built-in template for element node to be selected for wrapperNode.
This template, naturally, doesn't know about any parameters and it doesn't use the testParam parameter nor does it pass this parameter through. Solution : The solution is to specify a template matching wrapperNode that accepts a parameter named testParam and passes it through when it applies templates:.
Now when this transformation is applied on the provided XML document, the expected result is produced :. I think you want to put those tags INSIDE the top-level template, in which case it would generate the output within html and body tags. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. XSL named parameter 'with-param' using 'apply-templates' Ask Question.
Asked 11 years, 1 month ago. Active 2 years, 6 months ago. Viewed 45k times. Is there a better way to accomplish this? KevenK KevenK 2, 3 3 gold badges 24 24 silver badges 33 33 bronze badges.
0コメント