Is it possible to assign a value to a parameter of an imported stylesheet?
I was expecting something like
<xsl:import ... >
<xsl:with-param ...
</xsl:import>
but that is not allowed.
Also tunnel="yes" is forbidden in stylesheet parameters.
To use an XSLT parameterCreate an XsltArgumentList object and add the parameter using the AddParam method. Call the parameter from the style sheet. Pass the XsltArgumentList object to the Transform method.
The root element that declares the document to be an XSL style sheet is <xsl:stylesheet> or <xsl:transform>. Note: <xsl:stylesheet> and <xsl:transform> are completely synonymous and either can be used!
Remarks. An XSLT file can import another XSLT file using an <xsl:import> element. Importing an XSLT file is the same as including it except that definitions and template rules in the importing file take precedence over those in the imported XSLT file.
An XSLT style sheet can emit HTML <STYLE> elements, including CSS specifications, directly into the HTML that results from the XSLT transformation. This option works best when the number of CSS rules is small and easily managed.
Try this:
main.xsl
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:import href="import.xsl"/>
<xsl:variable name="param" select="'some-value'"/>
<xsl:template match="/">
<xsl:call-template name="foo"/>
</xsl:template>
</xsl:stylesheet>
import.xsl
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:param name="param" select="'default'"/>
<xsl:template name="foo">
<out><xsl:value-of select="$param"/></out>
</xsl:template>
</xsl:stylesheet>
An xsl:variable in an importing stylesheet can override an xsl:param in an imported stylesheet, and this effectively sets the value of the parameter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With