XML to another XML format transformation using XSLT

Discussion in 'XML' started by Binaryx, Apr 11, 2012.

  1. Binaryx

    Binaryx Guest

    I am new in xml, have read various documentations, but some practice
    examples would be more helpful than theory. I need transform one XML
    document to another XML document format(original standard) using XSLT
    transformation. Can someone specify how to make this correctly? Also, is
    there application that can do this?
     
    Binaryx, Apr 11, 2012
    #1
    1. Advertising

  2. Joe Kesselman, Apr 11, 2012
    #2
    1. Advertising

  3. Binaryx

    mikem789

    Joined:
    Apr 1, 2011
    Messages:
    3
    You'll find more relevant tutorials on the w3c schools site, this one look sparticualrly relevant to your needs, http://www.w3schools.com/xsl/xsl_transformation.asp

    In terms of software, most xml editors / parsers can do transforms for you, i'm quite into Liquid XML Studio, but there are other free editors bt I havent found any good free ones that I would be happy to recommend.
     
    mikem789, Apr 12, 2012
    #3
  4. Binaryx

    Peter Flynn Guest

    On 11/04/12 10:31, Binaryx wrote:
    > I am new in xml, have read various documentations, but some practice
    > examples would be more helpful than theory. I need transform one XML
    > document to another XML document format (original standard)


    What does "original standard" mean here?

    > using XSLT
    > transformation. Can someone specify how to make this correctly?


    Not unless we know what the two XML formats are.

    > Also, is there application that can do this?


    Same answer.

    XSLT is a language to let you write a transformation between formats. It
    is not a ready-made transformer.

    Here's an XML document from my notes app:

    ------------------------------ note.xml
    <note date="2010-04-14">
    <title>Shopping List</title>
    <list>
    <item>Sugar</item>
    <item>Butter</item>
    <item>Chocolate</item>
    <item>Cream</item>
    </list>
    </note>

    If I want this in XHTML, I would write something like:

    -------------------------------------- note2html.xsl
    <?xml version="1.0" encoding="utf-8"?>
    <xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="2.0">

    <xsl:eek:utput method="xhtml"/>

    <xsl:template match="/">
    <html>
    <head>
    <title>
    <xsl:text>Note dated </xsl:text>
    <xsl:value-of select="note/@date"/>
    </title>
    </head>
    <body>
    <xsl:apply-templates/>
    </body>
    </html>
    </xsl:template>

    <xsl:template match="title">
    <h1>
    <xsl:apply-templates/>
    </h1>
    </xsl:template>

    <xsl:template match="list">
    <ul>
    <xsl:apply-templates/>
    </ul>
    </xsl:template>

    <xsl:template match="item">
    <li>
    <xsl:apply-templates/>
    </li>
    </xsl:template>

    </xsl:stylesheet>

    Now I can run an XSLT2 processor like Saxon, eg

    $ java -jar saxon9he.jar -o:note.html note.xml note2html.xsl

    (or click something in an XML/XSLT IDE) and I get output like this:

    -------------------------------------- note.html
    <?xml version="1.0" encoding="UTF-8"?>
    <html>
    <head>
    <title>Note dated 2010-04-14</title>
    </head>
    <body>
    <h1>Shopping List</h1>
    <ul>
    <li>Sugar</li>
    <li>Butter</li>
    <li>Chocolate</li>
    <li>Cream</li>
    </ul>
    </body>
    </html>

    The idea is that you specify (in an XSLT template) what to do whenever a
    particular element type occurs (or a combination of elements types or
    other nodes). The result that you construct (within each template) is a
    combination of literal markup and XSLT features. An XSLT processor does
    all the rest: reading and parsing the source file, identifying which
    templates match which nodes, and building the result and putting it into
    an output file.

    ///Peter
    --
    XML FAQ: http://xml.silmaril.ie/
     
    Peter Flynn, Apr 14, 2012
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. clogwog
    Replies:
    0
    Views:
    442
    clogwog
    Oct 20, 2004
  2. Blue Gecko
    Replies:
    1
    Views:
    463
    Blue Gecko
    Oct 3, 2005
  3. Kevin Brown
    Replies:
    3
    Views:
    579
    Kevin Brown
    Aug 28, 2004
  4. SG
    Replies:
    2
    Views:
    867
    Mike Schilling
    Aug 15, 2007
  5. bosesuparna
    Replies:
    0
    Views:
    975
    bosesuparna
    Nov 25, 2011
Loading...

Share This Page