I have a big .net class and a few xslt files. I’m serializing my object to transform with my xslt files.
My class’ name is Application and it has an Applicant property which contains a collection of applications.
public class Application
{
public Person Applicant { get; set; }
}
public class Person
{
public List<Application> Applications { get; set; }
}
When I serialize an instance of my class, normally the Xml that I obtained contains z:Ref=”i18″ attributes to prevent infinite Xml creation to describe existing referenced properties. But this situation changes the required Xpath expressions that I have to write in my Xslt file.
Do I have a chance to serialize my object containing the real entity values instead of z:Ref tags for a specified depth?
Here is my serialization code:
public string Serialize(object input)
{
XmlDocument XmlDoc = new XmlDocument();
DataContractSerializer xmlDataContractSerializer =
new DataContractSerializer(input.GetType());
MemoryStream MemStream = new MemoryStream();
try
{
xmlDataContractSerializer.WriteObject(MemStream, input);
MemStream.Position = 0;
XmlDoc.Load(MemStream);
return XmlDoc.InnerXml;
}
finally
{
MemStream.Close();
}
}
Thanks in advance,
Anıl
No, basically. You should, however, be able to use something like:
and then use the xsl
keyfunction passing the@z:Refof the current node, wherezis anxmlnsalias tohttp://schemas.microsoft.com/2003/10/Serialization/– that will at least keep the usage the same throughout.Full example – xslt first (“my.xslt”):
Note that this walks 5 levels via the
$depthparameter (decrementing); the key part is the initialmatchon any element*[@z:Ref], which then useskeyto proxy the same request to the original element, as resolved via@z:Id. This means that when we are moving to child elements we just need to use something like:although we could obviously be more granular, for example:
Note also that to add a
Foo-specificmatch, you would add:to ensure that our
*[@z:Ref]match continues to handle reference-forwarding.And the C#: