views:

69

answers:

1

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 don'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?

A: 

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>
kristian