Hello all, OK I am not 100% sure if this can be done, but it would be great if could be.
Currently I have an XSLT that refernces an included XSLT file that it is re-used in several places. In this case I have a share facebook & print link in the included XSLT.
What I would like to do is to have a Macro setup to point directly to the included XSLT file. So I can call it from masterpages directly.
Here is the current setup for the template that references the include and it works just fine when used as an include
<!-- XSLT Template Includes --> <xsl:include href="../Common/ToolboxLinks.xslt"/>
<xsl:param name="currentPage"/>
<xsl:template match="/"> <!-- Some other stuff & logic -->
But on the page where I call it with just the macro and not as an include it doesn't work.
The error I get is as follows:
Error loading XSLT Common/ToolboxLinks.xsltThe variable or parameter 'currentPage' is either not defined or it is out of scope. at System.Xml.Xsl.XslCompiledTransform.LoadInternal(Object stylesheet, XsltSettings settings, XmlResolver stylesheetResolver) at System.Xml.Xsl.XslCompiledTransform.Load(XmlReader stylesheet, XsltSettings settings, XmlResolver stylesheetResolver) at umbraco.macro.CreateXsltTransform(XmlTextReader xslReader, Boolean debugMode) at umbraco.macro.getXslt(String XsltFile) at umbraco.macro.loadMacroXSLT(macro macro, Hashtable attributes, Hashtable pageElements)
Any ideas people? Has anyone even attempted something like this before?
Yes if I do that though, it will work with the version being called directly from the macro, but now the ones that refrence it using the include now don't work.
I get this error:
Error loading XSLT Article/DisplayArticleGallery.xslt The variable or parameter 'currentPage' was duplicated with the same import precedence. at System.Xml.Xsl.XslCompiledTransform.LoadInternal(Object stylesheet, XsltSettings settings, XmlResolver stylesheetResolver) at System.Xml.Xsl.XslCompiledTransform.Load(XmlReader stylesheet, XsltSettings settings, XmlResolver stylesheetResolver) at umbraco.macro.CreateXsltTransform(XmlTextReader xslReader, Boolean debugMode) at umbraco.macro.getXslt(String XsltFile) at umbraco.macro.loadMacroXSLT(macro macro, Hashtable attributes, Hashtable pageElements)
I think in that case I'd write an XSLT extension to reconstruct the currentPage variable in the second XSLT. If the $currentPage variable is null, then use the "currentPage" xml from the extension. I'm just not sure if you can test for null in XSLT?!
1) Put the xsl:param name="currentPage" into the INCLUDED FILE (ToolBoxLinks.xslt) ONLY - do not put it in the calling file. In theory that should work; its possible that Umbraco's validation at save may return an error, but ignore errors and try it anyway! Because basically by including the file, the xsl:param is available to your main xslt file. Pretty sure that should work.
2) Alternatively, try using xsl:import instead of xsl:include. That should also work.
3) Alternatively, modify your "toolboxLinks" template so it accepts a parameter, name "theCurrentPage" and pass it in from your main xsl file.
Then create a third XSLT file which also includes the file, and passes $currentPage into theCurrentPage param. But hopefully, 1 or 2 will work for you.
Excellent stuff Adz I tried your first suggestion by moving the <xsl:param name="currentPage"/> into the included XSLT file only and removing it from the other XSLT files that include/reference that XSLT file.
XSL include get processed first when they are read in so they need any params you are going to use in templates to be defined in the include file.
I'm a big fan of having a include file of helpers which can save global variables, functions etc. Makes life so much easier if you start coding from the off to allow for that.
Pondering including a "helpers" XSL file in the best practise package I'm knocking together.
Hiya guys, OK with Adz suggestion of moving the currentPage into the include worked fine until I updated my main XSLT with another include that will also work as a standalone macro.
It works perfectly fine as standalone macros, but the problem again now is that both of the included XSLT files now have currentPage in.
OK answering my own question - not ideally what I wanted to do but I added a wrapper XSLT file for the second item that was being included in the main XSLT file and pointed the macro to the wrapper file and not the included xslt file.
xsl include & reusing include as seperate macro
Hello all,
OK I am not 100% sure if this can be done, but it would be great if could be.
Currently I have an XSLT that refernces an included XSLT file that it is re-used in several places. In this case I have a share facebook & print link in the included XSLT.
What I would like to do is to have a Macro setup to point directly to the included XSLT file. So I can call it from masterpages directly.
Here is the current setup for the template that references the include and it works just fine when used as an include
This is the full XSLT for the included file:
But on the page where I call it with just the macro and not as an include it doesn't work.
The error I get is as follows:
Any ideas people?
Has anyone even attempted something like this before?
Warren :)
Have you tried adding:
<xsl:param name="currentPage"/>
Before the
<xsl:template match="/">
I can't see the $currentPage being defined in the included XSLT-file. Shouldn't it be there...
Yes if I do that though, it will work with the version being called directly from the macro, but now the ones that refrence it using the include now don't work.
I get this error:
Error loading XSLT Article/DisplayArticleGallery.xslt
The variable or parameter 'currentPage' was duplicated with the same import precedence.
at System.Xml.Xsl.XslCompiledTransform.LoadInternal(Object stylesheet, XsltSettings settings, XmlResolver stylesheetResolver)
at System.Xml.Xsl.XslCompiledTransform.Load(XmlReader stylesheet, XsltSettings settings, XmlResolver stylesheetResolver)
at umbraco.macro.CreateXsltTransform(XmlTextReader xslReader, Boolean debugMode)
at umbraco.macro.getXslt(String XsltFile)
at umbraco.macro.loadMacroXSLT(macro macro, Hashtable attributes, Hashtable pageElements)
I think you want to define your $currentPage before including the xslt:
Ah of course.
I think in that case I'd write an XSLT extension to reconstruct the currentPage variable in the second XSLT. If the $currentPage variable is null, then use the "currentPage" xml from the extension. I'm just not sure if you can test for null in XSLT?!
Or you could use a third XSLT that only defines the currentPage param and includes the ToolboxLinks one. Then you could call it directly.
Hi mate,
A couple of suggestions.
1) Put the xsl:param name="currentPage" into the INCLUDED FILE (ToolBoxLinks.xslt) ONLY - do not put it in the calling file. In theory that should work; its possible that Umbraco's validation at save may return an error, but ignore errors and try it anyway! Because basically by including the file, the xsl:param is available to your main xslt file. Pretty sure that should work.
2) Alternatively, try using xsl:import instead of xsl:include. That should also work.
(For more info on the logic behind why that should work, read http://www.xml.com/pub/a/2000/11/01/xslt/index.html )
3) Alternatively, modify your "toolboxLinks" template so it accepts a parameter, name "theCurrentPage" and pass it in from your main xsl file.
Then create a third XSLT file which also includes the file, and passes $currentPage into theCurrentPage param. But hopefully, 1 or 2 will work for you.
All the best
Adz.
Thanks Morten, I really thought that would solve it, but it didnt :(
The included versions now work fine, but the direct macro version doesn't.
I suppose that could be the last resort Sebastiaan to use another XSLT as like a proxy, but it's a shame if I can't just call the xslt include itself.
Anyone else want to suggest anything?
Warren
Excellent stuff Adz I tried your first suggestion by moving the <xsl:param name="currentPage"/> into the included XSLT file only and removing it from the other XSLT files that include/reference that XSLT file.
Great stuff. Karma given :)
XSL include get processed first when they are read in so they need any params you are going to use in templates to be defined in the include file.
I'm a big fan of having a include file of helpers which can save global variables, functions etc. Makes life so much easier if you start coding from the off to allow for that.
Pondering including a "helpers" XSL file in the best practise package I'm knocking together.
Pete
Hiya guys,
OK with Adz suggestion of moving the currentPage into the include worked fine until I updated my main XSLT with another include that will also work as a standalone macro.
It works perfectly fine as standalone macros, but the problem again now is that both of the included XSLT files now have currentPage in.
Suggestions again to get this to work please.
Thanks,
Warren :)
OK answering my own question - not ideally what I wanted to do but I added a wrapper XSLT file for the second item that was being included in the main XSLT file and pointed the macro to the wrapper file and not the included xslt file.
An example wrapper file:
Updated xslt include file (removed the <xsl:template match="/">)
That seems to me to be a perfectly valid and sensible solution Warren, why do you get a bad code smell?
is working on a reply...