Yes - you can use xml/xslt for generating html. Only issue with this approach is to get xml serialization of data - data-table supports it but its schema is convoluted as compared to say a hand-crafted xml - so writing xsl becomes a bit difficult. Then there is obvious performance cost - first datatore to datatable, then datatable to xml and then xml to xslt. You can avoid some by directly fetching xml from the database (that would also allow you to control the schema). Personally, I would go to xml/xslt route only if I have many such conversions to do.
You also have some alternatives:
User server side templating - for example, user aspx page or usercontrol and data-binding syntax to generate the html (use HttpServerUtility.Execute to get page html in service code)
My favorite is to return JSON object from service and do html generation in java-script. You can use client side templates for the purpose - see how to do it with microsoft way or using pure js templating engines such as jsTemplate or jTemplates
发布评论
评论(2)
是的 - 您可以使用 xml/xslt 生成 html。这种方法的唯一问题是获取数据的 xml 序列化 - 数据表支持它,但与手工制作的 xml 相比,它的模式很复杂 - 因此编写 xsl 变得有点困难。然后有明显的性能成本 - 首先从数据存储到数据表,然后从数据表到 xml,然后从 xml 到 xslt。您可以通过直接从数据库获取 xml 来避免一些问题(这也允许您控制架构)。就我个人而言,只有当我有很多这样的转换要做时,我才会使用 xml/xslt 路线。
您还有一些替代方案:
用户服务器端模板 - 例如,用户 aspx 页面或用户控件和数据绑定语法来生成 html(使用 HttpServerUtility.Execute 获取服务代码中的页面 html)
我最喜欢的是从服务返回 JSON 对象并在 java 脚本中生成 html。您可以使用客户端模板来达到此目的 - 请参阅如何使用 microsoft way< /a> 或使用纯 js 模板引擎,例如 jsTemplate 或 jTemplates
Yes - you can use xml/xslt for generating html. Only issue with this approach is to get xml serialization of data - data-table supports it but its schema is convoluted as compared to say a hand-crafted xml - so writing xsl becomes a bit difficult. Then there is obvious performance cost - first datatore to datatable, then datatable to xml and then xml to xslt. You can avoid some by directly fetching xml from the database (that would also allow you to control the schema). Personally, I would go to xml/xslt route only if I have many such conversions to do.
You also have some alternatives:
User server side templating - for example, user aspx page or usercontrol and data-binding syntax to generate the html (use HttpServerUtility.Execute to get page html in service code)
My favorite is to return JSON object from service and do html generation in java-script. You can use client side templates for the purpose - see how to do it with microsoft way or using pure js templating engines such as jsTemplate or jTemplates
您可以使用本机 XslTransform 类,也可以选择众多开源实现之一。
You can use native XslTransform class, or you can choose one of many opensource implementations.