Force xslt document() to load an external document over HTTP rather than directly from the file system
Within my ASP.NET application, I'm loading an XML file into an XSLT with the document()
method, as follows:
<xsl:variable name="more-xml" select="document('generateXml.ashx')" />
This works fine when I run it locally, but fails when I deploy it to the server because the server finds generateXml.ashx
through the file system, so it isn't processed by IIS.
If I hard-code the URL like this:
<xsl:variable name="more-xml" select="document('http://server/app/generateXml.ashx')" />
Then the document address is always resolved over HTTP, so it works consistently - but I do开发者_JAVA技巧n't want to hard-code the URL into the XSLT. Is there a way to force document() to use HTTP instead of FILE for a relative path?
Instead of loading the XML with the document() method within the XSLT, use an XmlArgumentsList
to populate an <xsl:param>
with the XML.
XsltArgumentList args = new XsltArgumentList();
args.AddParam("more-xml", string.Empty, myXmlDocument.CreateNavigator().SelectChildren(XPathNodeType.All));
// pass the argument list to the transform
myXslCompiledTransform.Transform(sourceXml, args, myXmlWriter);
Then in the XSLT:
<xsl:param name="more-xml"></xsl:param>
精彩评论