Connecting Tech Pros Worldwide Forums | Help | Site Map

XML to XML Transformation

Will
Guest
 
Posts: n/a
#1: Jul 20 '05
I was thrust into XML about 2 weeks ago and don't know much yet. From
another department in the corp I am receiving an XML file which
concatenates nodes all on one line i.e.
<car><make>ford</make><color>red</color><year>2001</year></car><car><make><mb>
etc. etc. etc. Some lines are over 300 characters long. I need to
translate this spagetti XML into something which is humanly readable.
I probably need to use XSL however I'm not sure what I need to do.
Any help will be much appreciated.

Dimitre Novatchev
Guest
 
Posts: n/a
#2: Jul 20 '05

re: XML to XML Transformation



"Will" <william.cook@kla-tencor.com> wrote in message
news:8506d1f6.0310311244.49a0856c@posting.google.c om...[color=blue]
> I was thrust into XML about 2 weeks ago and don't know much yet. From
> another department in the corp I am receiving an XML file which
> concatenates nodes all on one line i.e.
>[/color]
<car><make>ford</make><color>red</color><year>2001</year></car><car><make><m
b>[color=blue]
> etc. etc. etc. Some lines are over 300 characters long. I need to
> translate this spagetti XML into something which is humanly readable.[/color]

View the xml file using IE or Mozilla -- they provide an appealing,
aesthetic looking layout with collapse/expanding of contents of elements.
[color=blue]
> I probably need to use XSL however I'm not sure what I need to do.[/color]

If you decide to use XSLT (if, because the first approach above is really
what one needs in order to view an xml file), you need to run the identity
transformation, but specify:

indent="yes"

for the xsl:output element.


=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL


Will Cook
Guest
 
Posts: n/a
#3: Jul 20 '05

re: XML to XML Transformation



Dimitre,
Thanks for your response. My problem is I have to use this XML file as
input to be processed by an application I am writing. It would be much
easier if I could read a line of input which contained a start tag, the
value, the end tag instead of having to parse a 300+ character line
looking for all the various tags used. I looked up 'identity
transformation' in the XML books I have, Handbook 4.0 and Definitive
XML, and couldn't find a reference. Could you be a little more
specific. Sorry for being a pest.
-->Will


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Dimitre Novatchev
Guest
 
Posts: n/a
#4: Jul 20 '05

re: XML to XML Transformation


> Thanks for your response. My problem is I have to use this XML file as[color=blue]
> input to be processed by an application I am writing. It would be much
> easier if I could read a line of input which contained a start tag, the
> value, the end tag instead of having to parse a 300+ character line
> looking for all the various tags used. I looked up 'identity
> transformation' in the XML books I have, Handbook 4.0 and Definitive
> XML, and couldn't find a reference. Could you be a little more
> specific. Sorry for being a pest.[/color]

The identity transform is defined in the XSLT spec
(http://www.w3.org/TR/xslt#copying):

"For example, the identity transformation can be written using xsl:copy as
follows:
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>"

Therefore this transformation:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output omit-xml-declaration="yes" indent="yes"/>

<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>

</xsl:stylesheet>

when applied (with Saxon 6.5.3) on this source.xml:

<car><make>ford</make><color>red</color><year>2001</year></car>


produces this result:

<car>
<make>ford</make>
<color>red</color>
<year>2001</year>
</car>


=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL







Michael Wein
Guest
 
Posts: n/a
#5: Jul 20 '05

re: XML to XML Transformation


On 31 Oct 2003 12:44:23 -0800, Will wrote:
[color=blue]
> I am receiving an XML file which concatenates nodes all on one line i.e.
> <car><make>ford</make><color>red</color><year>2001</year></car><car><make><mb>
> etc. etc. etc. Some lines are over 300 characters long. I need to
> translate this spagetti XML into something which is humanly readable.[/color]

Then you need a pretty printer/beautifier/code reformatter rather than a
transformation tool! Basically any reasonable XML editor provides such a
feature, e.g. JEdit with the XML plugins.
[color=blue]
> I probably need to use XSL however I'm not sure what I need to do.
> Any help will be much appreciated.[/color]

No, I can't recognise where XSL might make sense in your scenario.
--
Michael Wein
Michael Wein
Guest
 
Posts: n/a
#6: Jul 20 '05

re: XML to XML Transformation


On 31 Oct 2003 21:51:07 GMT, Will Cook wrote:
[color=blue]
> Thanks for your response. My problem is I have to use this XML file as
> input to be processed by an application I am writing.[/color]

Then it doesn't have to be human readable as stated in your original
posting but rather machine readable what makes a *huge* difference!

Why not just use a standard XML parser like Xerces, Saxon, ... and access
the file using DOM or SAX APIs? Either I am missing some crucial aspect or
you are lacking basic parsing knowledge.
--
Michael Wein
Will Cook
Guest
 
Posts: n/a
#7: Jul 20 '05

re: XML to XML Transformation


Dimitre,
Thank you so very much. With you help the sun is starting to peek
through these XML clouds :-)

-->Will
Why Let Reality Wreck Your Day?!?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
keyur shah
Guest
 
Posts: n/a
#8: Jul 20 '05

re: XML to XML Transformation


Basically, you can simply open your XML file in browsers supporting XML
such as IE and you would be able to see the XML formatted properly as
TAGS.

But, if you want to have the XML formatted in a particular style as
paragraph and so on,, you would need to develop/build an XSL file, and
do a transformation by applying XSL on top of XML in order to make it
formatted and human readable.



Keyur Shah
Verizon Communications
732-423-0745

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Steve Slatcher
Guest
 
Posts: n/a
#9: Jul 20 '05

re: XML to XML Transformation


Will Cook wrote:
[color=blue]
> I looked up
> 'identity transformation' in the XML books I have, Handbook 4.0 and
> Definitive XML, and couldn't find a reference.[/color]

http://www.dpawson.co.uk/xsl/sect2/identity.html

But I think using a browser is the simplest idea. You can collapse
everything you don't want to see.


Closed Thread