In my xslt i have a piece of C# code :
public string CleanForTableTags(string pContent){
string input = String.Concat("<root>", pContent, "</root>");
System.Xml.Linq.XDocument doc = System.Xml.Linq.XDocument.Parse(input, System.Xml.Linq.LoadOptions.PreserveWhitespace);
var valueWithinTags = doc.Root.Element("table").ToString();
string[] values = Regex.Matches(valueWithinTags, @"<.*?>")
.Cast<Match>()
.Select(o => o.Groups[0].Value)
.ToArray();
System.Guid d = System.Guid.NewGuid();
string s = pContent.Replace(valueWithinTags, d.ToString());
return s;
}
as u can see i use: System.Xml.Linq
in my webconfig ive got :
<compilation debug="true">
<assemblies>
<add assembly="WindowsBase, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Drawing.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Data.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/></assemblies>
</compilation>
And still i am getting :
The type or namespace name ‘Linq’ does not exist in the namespace ‘System.Xml’ (are you missing an assembly reference?)
What am i doing wrong?
I am using VS 2008. All paths to Dlls are correct, if i use same piese of code from a class it work without problems, but as soon it is used inside of xslt, im getting error
Next problem :
now its failing on
string[] values = Regex.Matches(valueWithinTags, @"<.*?>")
.Cast<Match>()
.Select(o => o.Groups[0].Value)
.ToArray();
'System.Text.RegularExpressions.MatchCollection' does not contain a definition for 'Cast' and no extension method 'Cast' accepting a first argument of type 'System.Text.RegularExpressions.MatchCollection' could be found (are you missing a using directive or an assembly reference?)
What do you mean exactly by “inside of xslt”?
XSLT is just an xml file with transformations. Or are you using the
msxslnamespace to include a piece of script using C#?In that case you probably need to include
<msxsl:assembly name="System.Xml.Linq" />as well as using
<msxsl:using namespace="System.Xml.Linq" />inside the transformations file.Here’s an example of how to include a piece of script inside the transformation: http://docs.composite.net/FAQ/Developer?q=How+to+run+CSharp+function+in+XSLT%3F
Regarding the second part, about
Cast<>, that is an extension method inSystem.Linq.Enumerableso adding theSystem.Linqnamespace as a “using” should suffice (also make sureSystem.Coreis included as an assembly as well).