Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   XML (http://www.velocityreviews.com/forums/f32-xml.html)
-   -   XML to another XML format transformation using XSLT (http://www.velocityreviews.com/forums/t945297-xml-to-another-xml-format-transformation-using-xslt.html)

Binaryx 04-11-2012 09:31 AM

XML to another XML format transformation using XSLT
 
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?

Joe Kesselman 04-11-2012 12:42 PM

Re: XML to another XML format transformation using XSLT
 
There's a lot of good tutorial information on DeveloperWorks:
http://www.ibm.com/developerworks/xml/

Also, most XML parsers and XSLT processors come with some simple samples.

Read through those, and come back to us if you have specific questions.


--
Joe Kesselman,
http://www.love-song-productions.com...lam/index.html

{} ASCII Ribbon Campaign | "may'ron DaroQbe'chugh vaj bIrIQbej" --
/\ Stamp out HTML mail! | "Put down the squeezebox & nobody gets hurt."

mikem789 04-12-2012 12:33 PM

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.

Peter Flynn 04-14-2012 10:20 PM

Re: XML to another XML format transformation using XSLT
 
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:output 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/


All times are GMT. The time now is 06:21 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.