Dynamic XSL file

2019-08-21 17:24发布

问题:

I have 3 XSL files which have paths in them to something like C:\templates\Test\file.pdf

This path isn't always going to be the same and rather than having it hard coded in the XSL, I'd like it so that the path C:\templates\test\ is replaced with a tag [BASEPATH] and when I read in the xsl file into the XSLTransform object (yes I know it's been deprecated, I may move over to the XSLCompiledTransform at the same time), I'd like the tag [BASEPATH] to be replaced with the absolute file path of the web folder (or Server.MapPath("~") seeing as it is in .net)

I thought I may be able to make an XSLLoader aspx page which takes the name of the XSL file through the querystring and then returns the XSL file via xml content-type. When I try this, I get a 503 error though so I'm not sure if you can pass urls like this into the XSLTransform.Load method.

Any ideas what to do?

回答1:

Have you looked at XSL parameters?

<xsl:param name="basepath" select="'C:\Users\Graeme\'" />

<xsl:value-of select="document(concat($basepath, 'test.pdf'))" />

Then, most decent XSLT engines have a way to set a root level parameter from outside.