Reputation: 33
I have an XSL file (template.xsl) like the following:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:import href="1.xsl" />
<xsl:import href="2.xsl" />
<xsl:import href="3.xsl"/>
<xsl:import href="4.xsl"/>
...
The file works without any issues on all non-webkit browsers that I have tested on. Though, I want it to work on webkit browsers too. So, I need a way to merge all the xsl:import into the main file. So, I can see if that fixes the problem. I have read the solutions provided on other threads such as this one:
Recursively merging multiple XSLT stylesheets
I can see that the solution provided uses this Style Sheets script server side:
<?xml version="1.0" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="xsl:include">
<xsl:apply-templates select="document(@href)/xsl:stylesheet/*"/>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
Though, I do not know how to use it (other than replacing my xsl:import with xsl:include). Do I place that on my template.xsl file and where? Do I put it on a new XSL file and use a php script to load it, in order to merge the XSL files. It would be nice if I could have an example. The result I need is for me to serve the browser with one XSLT with no includes/imports. I want an XSL file I could save after the merge, so I get rid of the other files. I do not want to merge the files server side unless I have to. So, if there is a tool that merges the files. That would be ok too. Thank you.
Upvotes: 3
Views: 1443
Reputation: 57169
I agree with Michael's comments that the question is actually too broad, but what I read from your question is that you want your stylesheet to work on browsers and that some browsers do not allow xsl:import
or xsl:include
.
If you do not have an XSLT development environment, I strongly suggest you get yourself one, as Michael already said, many exist. It will save yourself a lot of pain. Suggestions include: oXygen (in my not so humble opinion, the best), Visual Studio (only XSLT 1.0, but suffices for your task as browsers only support XSLT 1.0), Stylus Studio, Eclipse.
Though, I do not know how to use it (other than replacing my xsl:import with xsl:include).
You can use it as with any XSLT, but in this case, your XSLT that needs to be merged is the source, to be transformed with the XSLT you show above. Just run it from the commandline with your favorite processor.
Yes, you can replace xsl:import
in that stylesheet, but be aware that importing is not the same as including. You may need to manually adjust the import precedence afterwards, which gets lost after you insert these stylesheets in situ.
Do I place that on my template.xsl file and where?
I don't understand the question. You say you want to replace your original XSLT with one that has the imports and includes inserted, so my guess is you know this answer best, but I assume you want to replace the output over your original stylesheet.
Do I put it on a new XSL file and use a php script to load it, in order to merge the XSL files.
I don't know where and how PHP comes into place. You said you wanted to load it in the browser. So the result of the transformation should, after testing locally, be made accessible to the browser.
I want an XSL file I could save after the merge, so I get rid of the other files. I do not want to merge the files server side unless I have to.
Yes, see above, just run the stylesheet you already provided and safe the output.
do not want to merge the files server side unless I have to. So, if there is a tool that merges the files.
You already gave a tool yourself. You can use that as with any XSLT file, just run it from the commandline (parameters differ per processor, but usually you can see them by using the -?
or '-h` as arguments, or just see the documentation of your processor).
Bottom line with all of this is, that it appears to me that you are trying to achieve something, but you do not yet know what it is that you are trying to achieve. My suggestion would be to experiment a bit with XSLT (definitely not in the browser!) and once you understand the concepts, try to do the scenario you already suggested yourself: run the merge-stylesheet against your original stylesheet.
Of course, this is a lot of trouble to go through, especially considering that xsl:import
is not the same as just including the contents of the stylesheet in that place. You may be better of by copying the items by hand, use the XSLT editor to show you were errors arise, fix them, save it, publish it.
Upvotes: 2