XSLT from a XSD spec.

G

Gilgamesh

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
 
J

Joseph Kesselman

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.
 
P

Peter Flynn

Gilgamesh said:
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 <a1> element 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
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</ex> né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</add> sé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</add> a scáil
<add type="gloss" hand="M">.i. a fir</add> día coemchill</l>
</lg>
</body>
</text><lb n="438"/>.i. am<ex>al</ex> téit carpat <add type="gloss"
hand="M">&lstrok; claidab</add> serda 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></add> sund
<sic>incond</sic> ilid. ar is cul in foc<ex>ul</ex> gná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</add> a<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</add> ba bés
ni thías.</l>
</lg>
</body>
</text>
</p>

///Peter
 
G

Gilgamesh

Peter Flynn ha escrito:

Hi!
Usually because there is no obvious way to know what HTML
your <a1> element 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
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
 
J

Joe Kesselman

Gilgamesh said:
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.
 
M

Manuel Collado

Gilgamesh escribió:
Peter Flynn ha escrito:

Hi!


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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top