tags:

views:

148

answers:

5

Hi all is there any application to generate a XSL Stylesheet from a XML file, I have a very complex XML file with me here which is a well-formed SVG file. Is there any software application to convert XML to XSL??

+5  A: 

XSL files contain instructions of how to transform a source XML file to another format (may be XML, too). So there is no possibility for a software to transform an XML file to an XSL Stylesheet without having further information on how to do that.

It's like wanting to have a PHP script out of an HTML file. To clarify: A php script could produce the HTML page

<html><body>hello world</body></html>

You cannot deduce what the original script looked like. It may be a simple echo()-call or the result of a complex decoding operation, etc.

The same is for the transformation from XML to XSL. You have to do it by yourself, as a software cannot know how to transform an XML-result to its underlying XSL-transformation sheet.

Simon
-1 - It certainly is possible to transform a source XML file to XSL. It is also possible to transform a source HTML file to a PHP script.
Don Roby
You do not have a unique way to do this... <html><body>hello world!</body></html> could be created from A N Y PHP-script! It may be the result of a MySQL-query or simply the command echo "<html><body>hello world..."... Same behaviour for XML -> XSL!
Simon
Certainly there's no unique way to do it. But if you have a specific pattern for how the XSL is to be produced from the source XML, it can be done.
Don Roby
So is there a software that is able to create that pattern?
Simon
No. That's what we're for.
Don Roby
Agree. But why did you downvote me? The questioner wanted to know if there's a software able to do that. :)
Simon
@Simon: I did not vote you down but better remove the sentence "So there is no possibility to transform an XML file to an XSL Stylesheet". It does not make sense as pointed out by donroby.
Viet
Now it should be clear... at least i hope so
Simon
I downvoted. But I've now upvoted based on your clarification.If the OP is after magic, he'll indeed be disappointed.
Don Roby
A: 

IntelliJ can generate an XSD from an XML file and visa versa. I'm not sure if the community edition has the capability, but the licensed version can.

duffymo
XSD != XSL(T) :)
Simon
+1  A: 

No, but you could use some solutions that help you create the XSL files easier. E.g. Altova XMLSpy

thelost
+1  A: 

XSL can be used to produce XSL from XML. But as XSL already is XML, this simple fact doesn't get you much specifically.

Can you specify some source XML and the desired XSL? Without knowing what you're trying to accomplish, not much more can be said.

There are some interesting examples of such in Chapter 10 (Code Generation) of

XSLT Cookbook

Don Roby
+2  A: 

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"&gt;

  <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"&gt;

      <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>
Jukka Matilainen