Using Parameters in XSL Select Statements

Using Parameters in XSL Select Statements

Given the XML file:


Sometimes we want to display name1 and sometimes name2. We figured that perhaps we could set a parameter.

Then we could pass in the name of the attribute as the value using the addparameter method on the processor object. Then maybe we’d access the required attribute like this:

or "@$temp" but you get the idea)

You’ve got the right idea, though it’s not quite that simple. What you need to do is pass the name of the parameter, then compare against the name:

By including the select statement in the parameter, you guarantee that if no parameter is passed that the first name will always be used.


Share the Post: