a beginner question on XSLT

前端 未结 3 1561
终归单人心
终归单人心 2021-01-13 16:50

I just started learning XSLT,now I am following some on-line tutorial of it,and I just have a simple question now:

suppose we have a original xml file,do we need to

3条回答
  •  花落未央
    2021-01-13 17:19

    Sorry for the mis clarification.I need to convert this .svg file to a pdf,I am just now at the beginning of the development,so really confused about the first step.Also,I would like to know,if my initial input is a .svg file,do I have to explicitly transform it into an .xml before I can start using XSLT?

    An SVG file is an XML file in the SVG namespace. Whether or not you need to transform that XML depends on how you're going to use it. If you were going to do a batch print using something like Inkscape (an SVG editor), you wouldn't.

    If you are going to use something like XSL-FO, you would. The answer by @Zoltan Hamori is kind of misleading. You can use saxon to perform an XSLT transform (creating the XSL-FO), but you will still need an XSL-FO processor to create the PDF from the XSL-FO.

    Zoltan mentions FOP (Apache Formatting Objects Processor), but he makes it sound like FOP and XSL-FO are the same; they're not. His code example is an XSL-FO table (XML in the fo namespace). You would need a processor such as FOP, RenderX, Antenna House, etc. to create the PDF from the XSL-FO.

    Basically what you need is:

    1. XML input (this would be your SVG file)
    2. XSLT transform to create the XSL-FO.
    3. XSL-FO processor to create the PDF from the XSL-FO

    Learning the XSL-FO at the same time you're learning XSLT is going to be tough, but I will show you two ways to output an SVG in a PDF.

    The first way is to reference the SVG file using fo:external-graphic.

    The second way is to embed the SVG XML directly into the XSL-FO using fo:instream-foreign-object.

    Since the XML input is the SVG XML, I would go with the second option. However, I'm not sure what effect this has on processing time and which way would be more efficient.

    I've shown an example below. Since I showed both ways to output an SVG, this will create a 2 page PDF. Each page will have the SVG graphic.

    Notes

    • For testing, I used an example SVG file that came with Inkscape. (I removed most of the SVG XML from the XSL-FO output because it's pretty big.)
    • For my XSLT processor, I used Saxon-HE 9.2.0.6.
    • For my FO processor, I used Apache FOP Version 0.95 (although I much prefer RenderX).

    Also

    • Both Saxon-HE and Apache FOP are free.
    • If you give me your email, I can send you the SVG file I used along with the full XSL-FO output. I can also send you the PDF that was created.

    XSLT 2.0

    
      
      
    
      
      
        
          
        
      
    
      
        
          
            
              
            
          
          
            
              
                
                
                
                
                  
                
              
            
          
        
      
    
    
    

    XSL-FO (created by Saxon from SVG input and XSL stylesheet)

    
    
       
          
             
          
       
       
          
             
                
                
                  
                    
                  
                
             
          
       
    
    

    Hope this helps.

提交回复
热议问题