I have a load of XSLT from a third party which i need to use to transform some data.
If I use xsltproc it works fine and outputs data as expected.
I have the following C# code to try and use it in-process:
sXML is the lump of XML oJob.ContentTemplate is the local file path to the XSLT file
try
{
using (StringWriter oOutputString = new StringWriter())
{
using (XmlTextWriter oOutputWriter = new XmlTextWriter(oOutputString))
{
using (StringReader oInputString = new StringReader(sXML))
{
using (XmlTextReader oInputReader = new XmlTextReader(oInputString))
{
XslCompiledTransform oXSLTTransform = new XslCompiledTransform();
oXSLTTransform.Load(oJob.ContentTemplate, XsltSettings.TrustedXslt, new XmlUrlResolver());
oXSLTTransform.Transform(oInputReader, oOutputWriter);
String sHTML = oOutputWriter.ToString();
}
}
}
}
}
catch (Exception e)
{}
The exception thrown is:
Additional information: Cannot find the script or external object that implements prefix 'http://dlxs.org'.
The XSLT is fairly complicated and I don't understand most of it currently. Is there a way I can get this working without delving too far into the XSLT?
Visual Studio 2010 should support EXSLT right?
Edit : If i enable debug and step into it I can see the error on the line:
<xsl:import href="../../lib/xslfunctions.xsl"/>
......
<xsl:when test="contains($BibRegions, dlxs:normAttr($searchRgn))">
These functions should be included already, one of the local XSLT files contains this:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:str="http://exslt.org/strings" xmlns:exsl="http://exslt.org/common" xmlns:func="http://exslt.org/functions" xmlns:dlxs="http://dlxs.org" extension-element-prefixes="str exsl dlxs func" exclude-result-prefixes="str exsl dlxs func">
<!-- extension functions -->
<func:function name="dlxs:normAttr">
<xsl:param name="attr"/>
<!-- strip out spaces,commas,question marks -->
<xsl:variable name="temp" select="translate($attr,' ,?','')"/>
<func:result select="translate($temp,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')"/>
</func:function>
.....
</xsl:stylesheet>
Is it that Visual Studio can't open these files because they use UNIX paths or because it can't open the local files due to security issues?
Edit 2 :
The extensions that I'm using are:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:str="http://exslt.org/strings"
xmlns:exsl="http://exslt.org/common"
xmlns:func="http://exslt.org/functions"
xmlns:dlxs="http://dlxs.org"
extension-element-prefixes="str exsl dlxs func"
exclude-result-prefixes="str exsl dlxs func">
I'm very much an XSLT beginner so aren't sure what you need.
Thanks for all of the help.
I couldn't get this working using any of the native .NET libraries so worked around it. The program that this is used in is only ever intended to be run once to populate a database so performance isn't incredibly important. For those of you who are interested here is my solution. I use XSLTProc.exe to transform the data, streaming out to disk in a temporary file and then read the output back in again. Nasty but works.