Search code examples
xmlxsltxsl-fo

Is there any application to generate XSL for XML?


Is there any application to generate an XSL Stylesheet from an XML file? I have a very complex XML file, which is a well-formed SVG file.

Is there any software application to convert XML to XSL?


Solution

  • Based on your previous question, I assume you want to create an XSL-FO file from an SVG image.

    One option would be to just include the SVG image inline in a fo:instream-foreign-object. A complete example (using this SVG image):

    <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
    
      <fo:layout-master-set>
        <fo:simple-page-master master-name="master">
          <fo:region-body />
        </fo:simple-page-master>
      </fo:layout-master-set>
    
      <fo:page-sequence master-reference="master">
        <fo:flow flow-name="xsl-region-body">
          <fo:block>
            <fo:instream-foreign-object>
    
              <svg xmlns="http://www.w3.org/2000/svg"
                   width="200" height="200">
                <circle cx="100" cy="100" r="50" stroke="black"
                        stroke-width="5" fill="red" />
              </svg>
    
            </fo:instream-foreign-object>
          </fo:block> 
        </fo:flow>
      </fo:page-sequence>
    
    </fo:root>
    

    Another option would be to refer to the SVG image from a fo:external-graphic:

    <fo:external-graphic src="Svg_example4.svg"/>
    

    If you want automate this, you could just write a XSLT which transforms the SVG to a XSL-FO document with the SVG embedded:

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                    version="1.0">
      <xsl:template match="/">
    
        <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
    
          <fo:layout-master-set>
            <fo:simple-page-master master-name="master">
              <fo:region-body />
            </fo:simple-page-master>
          </fo:layout-master-set>
    
          <fo:page-sequence master-reference="master">
            <fo:flow flow-name="xsl-region-body">
              <fo:block>
                <fo:instream-foreign-object>
                  <xsl:copy-of select="." />
                </fo:instream-foreign-object>
              </fo:block> 
            </fo:flow>
          </fo:page-sequence>
    
        </fo:root>    
    
      </xsl:template>
    </xsl:stylesheet>