Including an XML file in an XML/XSL file

后端 未结 5 1501
时光说笑
时光说笑 2020-12-02 17:40

So currently I\'m doing some XML-> XSLT-> (HTML5/CSS3) work. Right now I have a menu.xml file, and I\'d like to include it in either the XSL file or the XML page. I\'ve done

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-02 18:15

    I. Here is how any XML document or fragment can be embedded in an XSLT stylesheet and used during the transformation:

    
     
     
    
     
       
         A
         B
         C
       
     
    
     
      
     
    
    

    When this transformation is applied on any XML document (not used in this example), the wanted result (just copying the XML) is produced:

    
       A
       B
       C
    
    

    Remember: Any XML can be embedded into an XSLT stylesheet, provided it is wrapped into a namespaced element (the namespace not the XSLT namespace) and this wrapping element is at the global level (a child of the (top) element).

    II. Accessing the XML menu file that resides in a separate XML file:

    To do this we have to change only slightly the previous example:

    
     
     
    
    
     
      
     
    
    

    If the menu XML file is in the 'menu.XML' file (in the same directory as the XSLT stylesheet file, then this transformation produces exactly the same result as the previous:

    
       A
       B
       C
    
    

    Do note: In both cases we are using the standard XSLT function document()

    Typically, one defines a global-level variable, whose value is the result of calling the document() function. Then this variable and its contents is accessed via XPath expressions during the transformation.

提交回复
热议问题