Unable to succeed in passing parameters in xsl (1.0) for . It seems that one cannot dynamically modify the content of the ‘select’. Below is an attempt that does not throw an error but fails to recognise the $entity parameter:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output cdata-section-elements="" encoding="UTF-8" indent="yes" method="xml" omit-xml-declaration="yes"/>
<xsl:param name="entity">CreditController[]</xsl:param>
<xsl:template match="/">
<xsl:element name="variable">
<xsl:attribute name="type">NameValuePair[]</xsl:attribute>
<xsl:apply-templates select="variable/*[@type='$entity']/item"/>
</xsl:element>
</xsl:template>
<xsl:template match="item">
<xsl:element name="item">
<xsl:attribute name="type">NameValuePair</xsl:attribute>
<xsl:element name="value">
<xsl:attribute name="type">String</xsl:attribute>
<xsl:value-of select="Code"/>
</xsl:element>
<xsl:element name="name">
<xsl:attribute name="type">String</xsl:attribute>
<xsl:value-of select="Code"/>-<xsl:value-of select="Value"/>
</xsl:element>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
Thanks in advance. Other posts seemed to recommend using and also setting ‘Mode’ attribute of the element. I did not win with either of these.
Replacing the entity variable with the string literal ‘CreditController[]’ works as expected.
In your XPath you surround your
$entitywith quotes, making it the string literal$entityand not a variable to be expanded.Remove the quotes: