473,401 Members | 2,068 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

XSLT from a XSD spec.

Hi.

I'm looking for an easy way to generate, automatically, an XSLT from an
XSD, to be applied to a XML file (conforming the previous XSD) and
generate an HTML. Many of you will tell me that this is nonsense, but
I think it can be done, given the condition that the XML file (as
specified in the XSD) always has a root element (although it would be
nice if the root element name could be a parameter of the XSLT), and a
given hierarchy of sub-elements, until a level N where there is a list
of data elements, like this:

<root>
<a1>
<b1>
<c1>
<d>D Value</d>
<e>E Value</e>
</c1>
<c2>
<d>another D Value</d>
<e>another E Value</e>
</c2>
</b1>
<b2>
<c3>
<d>D Value</d>
<e>E Value</e>
</c3>
</b2>
</a1>
<a2>
<b3>
<c4>
<d>D Value</d>
<e>E Value</e>
</c4>
</b3>
</a2>
</root>

The problem would be similar to have the tree structure of a directory
and sub-directories until the level of files, where the names of
directories and files would be the XML tags, and then for each file a
set of attributes, like size, date of creation, read-write permissions,
etc. And given this information, stored in a XML, conforming a given
XSD (what I actually have is the XSD), I would like to generate an HTML
with different levels of indentation or lists, until the point where I
process the file attributes, which I would like to show, say, as a
table with only one row.

Is there any tool that generates such (or similar to that) XSLT from
the XSD?

Thanks,

J C

Oct 4 '06 #1
5 1825
So what you're trying to do is generate a sample document from the schema?

There have been many tools that do this. The problem is, there's
generally a wide range of possible documents that match a given schema
and no clear way to decide which choices to make. You either need to
pick randomly and accept that your synthesized document may not in fact
be similar to any "real" document (due to semantic constraints not
expressed in the schema), or provide additional semantic info from some
other source.

There are a number of tools out there which will do this to a greater or
lesser extent, for the purposes of generating "churn" test suites. It
sounds like you ought to be investigating those before spending too much
time attempting to solve the same problem.
On the other hand, if you're just saying that you want to pretty-print
XML, and (unlike most attempts in that direction, which risk breaking
the document semantics when they insert the whitespace) you want to try
to use the schema to recognize then it's safe (ie, when you're dealing
with "element content")... I'm sure that too has been addressed many
times, but at least it's something that has a clearer definition.

On the other other hand, if you just want to pretty-print *with* the
risk that indentation will change the document's semantics, you don't
need the schema at all -- just track element nesting.
Oct 4 '06 #2
Gilgamesh wrote:
Hi.

I'm looking for an easy way to generate, automatically, an XSLT from an
XSD, to be applied to a XML file (conforming the previous XSD) and
generate an HTML. Many of you will tell me that this is nonsense,
Usually because there is no obvious way to know what HTML
your <a1element type ought to be output as, for example.

There is an infinite number of ways of doing it, so how do
you decide what is the "right" way for arbitrary XML.

I agree that if the element type names have an accepted
meaning in some language (eg <para>) then some of the
decisions are obvious, but more often they are not.
I think it can be done, given the condition that the XML file (as
specified in the XSD) always has a root element (although it would be
nice if the root element name could be a parameter of the XSLT),
The root element name of an XML document is always given
by the XPath expression /*[1]/name()
and a
given hierarchy of sub-elements, until a level N where there is a list
of data elements, like this:

<root>
<a1>
<b1>
<c1>
<d>D Value</d>
<e>E Value</e>
[snip]

But what makes you think all document types follow this pattern?
What you ask for may be valid for a very restricted subset of highly
specialist document types, but here's a paragraph of the kind of
XML I deal with:

<p><lb n="431"/>Fortched &lstrok; formolad fil híc &ampersir; conna
bitís gnee fortcheda<lb n="432"/><pb n="16"/foi sin dichned
&ampersir; dochned &ampersir; cennacros <frn lang="la">ut
q<ex>u</ex>idam d<ex>icu</ex>nt</frn>.<lb n="433"/bid
da<ex>no</exnéit guin <frn lang="la">ut
d<ex>icitu</ex>r</frn><text type="poem">
<body>
<lg type="quatrain" met="deibide">
<lb n="434"/>
<l>ro bé do lecht i farthe <add type="gloss" hand="M">.i. i
mmochai</add></l>
<lb n="435"/>
<l>iar do néit <add type="gloss" hand="M">.i. iar do
guin</addséol siraichthe. <add type="gloss"
hand="M">&lstrok; sírarde</add></l>
<lb n="436"/>
<l>ructhar i capp <add type="gloss" hand="M">.i. i carr</add>
i ndiaid phill <add type="gloss" hand="M">.i. eich</add></l>
<lb n="437"/>
<l>do racc <add type="gloss" hand="M">.i. do ben</adda scáil
<add type="gloss" hand="M">.i. a fir</adddía coemchill</l>
</lg>
</body>
</text><lb n="438"/>.i. am<ex>al</extéit carpat <add type="gloss"
hand="M">&lstrok; claidab</addserda tré chath corop amlaid<lb
n="439"/dech m'animsea tría chath nemna dochum nime. Culu<lb
n="440"/.i. forthched <add type="gloss" hand="M">.i. deichned
<frn lang="la">specialit<ex>er</ex></frn></addsund
<sic>incond</sicilid. ar is cul in foc<ex>ul</exgnáthach<lb
n="441"/acht ro thuill in filí .u. sund do línad na filidechta.
&lstrok; do<lb n="442"/dúaichnigud na foc<ex>u</ex>l tría
dígbail &ampersir; tria tórmach &ampersir; tria<lb n="443"/>
inchumscugud do dénam intib &ampersir; atát trí gnee fair .i.<lb
n="444"/díchned <add type="gloss" hand="M">&lstrok;
dechned</add&ampersir; dochned &ampersir; cennachros. Is é in
dichned <add type="gloss" hand="M">.i. dicennad</adda<lb n="445"/>
chend do gait dond c<ex>u</ex>l &ampersir; cen ní ele ina inad <frn
lang="la">ut dixit<lb n="446"/poeta</frn>.<text type="poem">
<body>
<lg type="quatrain">
<lb n="447"/>
<l>Dál ro dálus mór in baes</l>
<lb n="448"/>
<l>isind arus huas Druim <sup resp="BB">Lias</sup></l>
<mls n="7a" unit="folio"/>
<lb n="449"/>
<l>a mmo chomdiu a ri .rú. rá. <add type="gloss" hand="M">.i.
rún .i. rathmar sa</add></l>
<lb n="450"/>
<l>bui biu <add type="gloss" hand="M">&lstrok; bi</addba bés
ni thías.</l>
</lg>
</body>
</text>
</p>

///Peter
Oct 4 '06 #3

Peter Flynn ha escrito:

Hi!
Gilgamesh wrote:
Hi.

I'm looking for an easy way to generate, automatically, an XSLT from an
XSD, to be applied to a XML file (conforming the previous XSD) and
generate an HTML. Many of you will tell me that this is nonsense,

Usually because there is no obvious way to know what HTML
your <a1element type ought to be output as, for example.
Yep, that should be fixed, say, to H1 .. H9, or to different levels of
indentation, corresponding to the different depth in the tree.
There is an infinite number of ways of doing it, so how do
you decide what is the "right" way for arbitrary XML.

I agree that if the element type names have an accepted
meaning in some language (eg <para>) then some of the
decisions are obvious, but more often they are not.
I think it can be done, given the condition that the XML file (as
specified in the XSD) always has a root element (although it would be
nice if the root element name could be a parameter of the XSLT),

The root element name of an XML document is always given
by the XPath expression /*[1]/name()
and a
given hierarchy of sub-elements, until a level N where there is a list
of data elements, like this:

<root>
<a1>
<b1>
<c1>
<d>D Value</d>
<e>E Value</e>
[snip]

But what makes you think all document types follow this pattern?
What you ask for may be valid for a very restricted subset of highly
specialist document types, but here's a paragraph of the kind of
XML I deal with:
Well, the point is that I have the .XSD, and what is specified in the
..XSD is a simple hierarchy like the one shown above, and therefore all
XML conforming to that .XSD should have that form.

J C

Oct 5 '06 #4
Gilgamesh wrote:
Well, the point is that I have the .XSD, and what is specified in the
.XSD is a simple hierarchy like the one shown above, and therefore all
XML conforming to that .XSD should have that form.
As I said: Are you trying to generate a sample instance document that
illustrates the form, or are you trying to indent documents which have
that form? The former is possible modulo the choice points but solutions
are already available; the latter doesn't seem to need the schema.
--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Oct 5 '06 #5
Gilgamesh escribió:
Peter Flynn ha escrito:

Hi!
>Gilgamesh wrote:
>>Hi.

I'm looking for an easy way to generate, automatically, an XSLT from an
XSD, to be applied to a XML file (conforming the previous XSD) and
generate an HTML. Many of you will tell me that this is nonsense,
Usually because there is no obvious way to know what HTML
your <a1element type ought to be output as, for example.

Yep, that should be fixed, say, to H1 .. H9, or to different levels of
indentation, corresponding to the different depth in the tree.
Perhaps you just want to convert your XML to a nested lists HTML page. No
need to know the XSD for that.

Hope this helps.
--
Manuel Collado - http://lml.ls.fi.upm.es/~mcollado
Oct 5 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Christian Roth | last post by:
Hello, when using this "identity" processing sheet: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" encoding="iso-8859-1" /> ...
2
by: Philippe Poulard | last post by:
Hi, I need to define inside my stylesheet some xml structured datas, like this (this example works) : <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"...
1
by: Ken Philips | last post by:
If I want to use featurwes of Xslt Spec 2.0: Do I have to use an extension of .xslt2 or can use .xslt as well? Ken
3
by: Alex | last post by:
I stumbled upon this while developing a custom XPathNavigator. It appears that copy action for attributes is broken in the .net framework XSLT processor. The intent was to just copy the entities...
2
by: Lionel Fourquaux | last post by:
In .Net 1.1, System.Xml.Xsl.XslTransform cannot output directly a document in an encoding that cannot represent all the characters used (e.g. write in us-ascii for compatibility, and convert all...
2
by: Richard L Rosenheim | last post by:
Is it possible to include addition tags in a XSLT file, that the XSLT processor will, for all practical purposes, ignore? What I'm looking to do is to include a section to contain information...
0
by: Nithya Sampathkumar | last post by:
Hi, We are planning what features /improvements need to go in the next release for XSLT. We are making these decisions based on customer input and feedback. So I would like to hear your views on...
18
by: yinglcs | last post by:
Hi, I have a newbie XSLT question. I have the following xml, and I would like to find out the children of feature element in each 'features' element. i.e. for each <featuresI would like to...
14
by: Lee | last post by:
I have a xml file, here is sample part: <?xml version="1.0" encoding="UTF-8"?> <ProducsList> <Product id="1"> <SpecList> <Spec> <SpecLabel>Height</SpecLabel> <SpecValue>10</SpecValue>...
5
by: Lee | last post by:
I have a xml file, here is sample part: <?xml version="1.0" encoding="UTF-8"?> <ProducsList> <Product id="1"> <SpecList> <Spec> <SpecLabel>Height</SpecLabel> <SpecValue>10</SpecValue>...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.