Visualization of Xml documents

    I think it’s not a secret for many that xml is a fairly convenient way to store and transmit information. For the umpteenth time, I have come across in the literature a statement that in the future xml should replace html, and the appearance of xhtml is confirmation of this. But there is a nuance. all browsers know how to display html documents, but none of them knows how xml documents should be displayed. This is primarily due to the fact that when creating an xml-document you can enter your tags. I want to briefly (this is a very big topic, in fact) talk about the so-called "Transformation tables of xml-documents."
    I think that many are probably familiar with them, but I hope that this can be useful to someone, and, given my love of practice, I want to show everything with a very simple example


    What we have


    Consider a simple xml document:
    1.  
      Это заголовок Xml-документа
    2.  
    3.   
    4.    Habrahabr.ru
    5.    
    6.     В Хабрахабр заложена модель совместного творчества людей. Это
    7.     универсальное средство для всех представителей нового поколения
    8.     средств массовой информации.
    9.    
    10.   
    11.   
    12.    Bash.org.ru
    13.    
    14.     Вы добавляете цитату. После этого цитата попадает в Бездну, где
    15.     ее могут увидеть и проголосовать за нее наши посетители, читающие
    16.     сей суровый раздел.
    17.    
    18.   
    19.  

    If we try to view it in a browser, we will see something similar:


    There are several ways to visualize the contents of this document.
    You can connect a regular style sheet (css-file) or a conversion table to it.
    The conversion table is an xml-document, designed according to certain rules and having the extension .xslt.

    Suppose we need to display the information contained in an xml-document, for this we create a conversion table (the file will be called style.xslt):
    1. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    2. xmlns:msxsl="urn:schemas-microsoft-com:xslt"
    3. exclude-result-prefixes="msxsl">
    4.  
    5.  
    6.   
    7.    <xsl:value-of select="header" />
    8.    
    9.   
    10.  
    11.  
    12.  
    13.   
    14.  
    15.  
    16.  
    17.   
    18.     
    19.      http://
    20.     
    21.     
    22.     -
    23.  
    24.  


    You can connect the conversion table (to the original xml document of course) as follows: As a result, opening the same file in the browser, we will see the following:






    In a nutshell, how it works


    The conversion table describes three templates: document, items and item. When an xsl: apply-templates element is encountered in the template, it is replaced by what happens as a result of processing all the elements that satisfy the select expression (I just indicated the tag names, although there may be quite complex constructions there). Similarly, tag values ​​(xsl: value-of tag) and attributes for tags (xsl: attribute tag) are inserted.

    The document template forms the basis of the html page (html, head, body tags), and they insert the page title and the list of elements formed by the items template (List elements are formed by the items template).

    All conversion is done on the client side.

    This is just a small fraction of what transformation table technology can provide. Visual Studio has a convenient interface for working with them, including viewing the generated html.

    Also popular now: