469,960 Members | 2,660 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,960 developers. It's quick & easy.

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 1707
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Christian Roth | last post: by
2 posts views Thread by Philippe Poulard | last post: by
2 posts views Thread by Lionel Fourquaux | last post: by
2 posts views Thread by Richard L Rosenheim | last post: by
reply views Thread by Nithya Sampathkumar | last post: by
reply views Thread by rainxy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.