0

I have any param

<xsl:param name='param_1'/>
<xsl:param name='param_2'/>
...
<xsl:param name='param_100'/>

and any templates for items with id='1', id='2' ... id='100'

<xsl:template match='item[@id="1"]'>
   <xsl:value-of select='$param_1'/>
</xsl:template>

<xsl:template match='item[@id="2"]'>
   <xsl:value-of select='$param_1'/>
</xsl:template>
...
...
<xsl:template match='item[@id="100"]'>
   <xsl:value-of select='$param_100'/>
</xsl:template>

How to combine items into a single template?

Something like this:

<xsl:template match='item[@id="1" or @id="2" or @id="100"]'>
   <xsl:variable name='id' select='@id'/>
   <xsl:value-of select='$param_$id'/>
</xsl:template>

xsl:choose not good, items and params very much.

3
  • 1
    Does this answer your question? Indirect variable/parameter reference (name in another property / another variable) Commented Mar 25, 2021 at 9:33
  • Yes, but this don't worked if my param is dynamic: <xsl:param name="param_1" select="$variable_1"/>. At the output I get "$variable_1" Commented Mar 25, 2021 at 10:50
  • This is not how you are supposed to do it. Please see the actual link. Commented Mar 25, 2021 at 10:56

1 Answer 1

0

Instead of passing in 100 parameters, pass in a single parameter with internal structure:

<params>
  <param nr="1" value="x"/>
  <param nr="2" value="y"/>
  ..
</params>

Then it's simply

<xsl:template match="item[@id >= 1 and 100 >= @id]">
  <xsl:value-of select="$params//param[@nr=current()/@id]"/>
</xsl:template>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.