Reputation: 3079
I've been on this for half a day now. Couldn't get the simple variable override to work lol...
So here is the example: awesomecheck.xsl
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:variable name="enableAwesome" select="false()"/>
<xsl:template name="checkAwesomeness">
<xsl:if test="$enableAwesome">
This is awesome
</xsl:if>
</xsl:template>
</xsl:stylesheet>
Then I tried to override it using the following, example: realawesome.xsl
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:import href="test://xslt/awesomecheck.xsl"/>
<xsl:variable name="enableAwesome" select="true()"/>
</xsl:stylesheet>
When I call the realawesome.xsl
, it should technically override the variable and trigger the condition to print This is awesome
. But instead I'm getting some IO exception in awesomecheck.xsl
.
Any hint would be greatly appreciated... ugh.
PS: I've read through about 6 other links, couple of them were here on Stackoverflow, tried their solutions and way of doing it, and still no go. I also tried using with-param
and that was no go either... One of the more helpful link was: XSLT stylesheet parameters in imported stylesheets
If you have any better way of implementing/overriding it, please let me know. >.<
Upvotes: 0
Views: 566
Reputation: 117093
Not sure what you're trying to do, and what exactly is the problem you are encountering (if you are getting an error message, the smart thing is to reproduce it in your question). I suspect the real issue is with your testing method. Try the following:
external.xsl
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:variable name="var" select="false()"/>
<xsl:template name="mytemplate">
<xsl:value-of select="$var"/>
</xsl:template>
</xsl:stylesheet>
The "real" XSLT
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:import href="external.xsl"/>
<xsl:variable name="var" select="true()"/>
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<output>
<xsl:call-template name="mytemplate"/>
</output>
</xsl:template>
</xsl:stylesheet>
When the above is applied to any XML input, the result is:
<?xml version="1.0" encoding="UTF-8"?>
<output>true</output>
i.e. the variable in the imported document is overridden by the "local" value.
Upvotes: 1