Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8812277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:34:09+00:00 2026-06-14T03:34:09+00:00

I have a big .net class and a few xslt files. I’m serializing my

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T03:34:10+00:00Added an answer on June 14, 2026 at 3:34 am

    No, basically. You should, however, be able to use something like:

    <xsl:key name="ids" match="*[@z:Id]" use="@z:Id"/>
    

    and then use the xsl key function passing the @z:Ref of the current node, where z is an xmlns alias to http://schemas.microsoft.com/2003/10/Serialization/ – that will at least keep the usage the same throughout.


    Full example – xslt first (“my.xslt”):

    <?xml version="1.0" encoding="utf-8"?>
    <xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/"
      xmlns:dcs="http://schemas.datacontract.org/2004/07/"
    >
      <xsl:key name="ids" match="*[@z:Id]" use="@z:Id"/>
      <xsl:output method="xml" indent="yes"/>
    
      <xsl:template match="*[@z:Ref]">
        <xsl:param name="depth" select="5"/>
        <xsl:apply-templates select="key('ids', @z:Ref)">
          <xsl:with-param name="depth" select="$depth"/>
        </xsl:apply-templates>
      </xsl:template>
      <xsl:template match="*[@z:Id]">
        <xsl:param name="depth" select="5"/>    
        <xsl:value-of select="$depth"/>: <xsl:value-of select="name()"/><xsl:text xml:space="preserve">
    </xsl:text>
        <xsl:if test="$depth > 0">
          <xsl:apply-templates select="dcs:*">
            <xsl:with-param name="depth" select="($depth)-1"/>
          </xsl:apply-templates>
        </xsl:if>
      </xsl:template>
    </xsl:stylesheet>
    

    Note that this walks 5 levels via the $depth parameter (decrementing); the key part is the initial match on any element *[@z:Ref], which then uses key to 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:

    <xsl:apply-templates select="dcs:*"/>
    

    although we could obviously be more granular, for example:

    <xsl:apply-templates select="dcs:Foo"/>
    

    Note also that to add a Foo-specific match, you would add:

    <xsl:template match="dcs:Foo[@z:Id]"><!-- --></xsl:template>
    

    to ensure that our *[@z:Ref] match continues to handle reference-forwarding.

    And the C#:

    using System;
    using System.IO;
    using System.Runtime.Serialization;
    using System.Text;
    using System.Xml;
    using System.Xml.Xsl;
    [DataContract]
    public class Foo
    {
        [DataMember]
        public Bar Bar { get; set; }
    }
    [DataContract]
    public class Bar
    {
        [DataMember]
        public Foo Foo { get; set; }
    }
    static class Program
    {
        static void Main()
        {
            var foo = new Foo();
            var bar = new Bar();
            foo.Bar = bar;
            bar.Foo = foo;
            using (var ms = new MemoryStream())
            {
                var ser = new DataContractSerializer(typeof(Foo), new DataContractSerializerSettings {
                    PreserveObjectReferences = true
                });
                ser.WriteObject(ms, foo);
                Console.WriteLine(Encoding.UTF8.GetString(ms.GetBuffer(), 0, (int)ms.Length));
                Console.WriteLine();
                ms.Position = 0;
                var xslt = new XslCompiledTransform();
                xslt.Load("my.xslt");
                using (var reader = XmlReader.Create(ms))
                {
                    xslt.Transform(reader, null, Console.Out);
                }
            }
            Console.WriteLine();
            Console.WriteLine("press any key");
            Console.ReadKey();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a pretty big web application that I created last year using ASP.NET
I have implemented GZIP compression on a few of my ASP.NET pages, using a
in my Class I have a static dictionary of strings object which contains a
I have a object: public class MyObject { int id; string value; } I
I have Silverligth Unit test Application (.net 4.0) and I've added reference to my
In my C# / .NET application I have to check if a given executable
How to determine if a Class in .NET is big or small? Is it
I have a Silverlight app that consumes a WCF service in my asp.net application.The
I have to port a smaller windows forms application (product configurator) to an asp.net
I have a .NET 4 WCF service that is sending the client some big

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.