XSL (for example) declarative language, how MVC view over strong model?

As a huge fan of XSL, I am very happy to use xsl as a view in our own MVC framework in ASP.NET. The objects in the model are serialized under the hood using the .NET xml serializer, and we use pretty atomic xsl templates to declare how each object or property should be converted.

For example:

  <xsl:template match="/Article">
    <html>
      <body>
        <div class="article">
          <xsl:apply-templates />
        </div>
      </body>
    </html>
  </xsl:template>

  <xsl:template match="Article/Title">
    <h1>
      <xsl:apply-templates />
    </h1>
  </xsl:template>

  <xsl:template match="@*|text()">
    <xsl:copy />
  </xsl:template>

      

This mechanism allows us to quickly override the default matching patterns, such as matching patterns by the last item in a list or selected, etc. Also, the xsl extension objects in .NET allow us just a little extra grip that we need. Common common patterns can be split and included.

However

Even though I can ignore the xsl flaw (because the Visual Studio intellisense + snippets schema is really smooth, praise the VS team), the flaw is that it doesn't have intellisense over firmly anchored objects in the model, it really is. what is listening to me.

I've seen ASP.NET MVC + custom controls in action and is really starting to love it, but I'm wondering;

Is there a way to get some kind of intellisense over the XML we're iterating over, or do you know a language that offers the freedom and declarativeness of XSL, but has strongtype / intellisense advantages, like webforms / usercontrols / asp.net.mvc-view?

(I probably know the answer is no, and I found myself using Phil Haack, the downright cool mvc shizzle coming soon ...)

+1


source to share


2 answers


You can use the serialized (xml) form of your objects and edit it with VS XML editor (I am using VS2008).

Then map the xsd schema to this xml document. Use a schema that generates xsd, exe and uses it in serialization / deserialization.

You will see that you get intellisense for free !

Also, if you edit the schematic and add

    <xs: annotation>
      <xs: documentation>
        Helpful Explanation.
      </ xs: documentation>
    </ xs: annotation>


then the XML editor will not only prompt for possible element or attribute names and values , but it will also output a "Helpful Explanation" for each one, which contains the annotation data entered in the xml schema.

To learn how to link xml schema to XML document, either search local VS2008 help or find it on MSDN online or read it here .

Hope it helped.

Greetings,

Dimitar Novachev

+1


source


This is kind of off-topic, but down the road of building a CMS with xsl (t) and the pain of me recommending asp.net mvc for reasons other than intellisense. But it's nice.

I originally used xsl to extract a view from the data it made. But the designers were very worried, because everything looked like html. More angle brackets, etc. And I constantly talked: "But why don't I have a document with everything in it"

Xsl was also a plow and a very memory hungry. Mistakes in memory are awkward, and by the time you get to the end. And of course caching uses more memory.



There really was no looking back since we went with MVC, there is even the option to create your own view engine if you're feeling very adventurous. This way you could save some xsl wherever you felt the need.

In fact, there is already a project based on what is in the MVCContrib libraries .

Hope this helps your solution.

0


source







All Articles