XSLT from a XSD spec.

Discussion in 'XML' started by Gilgamesh, Oct 4, 2006.

  1. Gilgamesh

    Gilgamesh Guest

    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
     
    Gilgamesh, Oct 4, 2006
    #1
    1. Advertising

  2. 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.
     
    Joseph Kesselman, Oct 4, 2006
    #2
    1. Advertising

  3. Gilgamesh

    Peter Flynn Guest

    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 <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
    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</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
     
    Peter Flynn, Oct 4, 2006
    #3
  4. Gilgamesh

    Gilgamesh Guest

    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 <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
    > 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
     
    Gilgamesh, Oct 5, 2006
    #4
  5. 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
     
    Joe Kesselman, Oct 5, 2006
    #5
  6. 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 <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.


    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
     
    Manuel Collado, Oct 5, 2006
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ken Philips
    Replies:
    3
    Views:
    371
    John Keyes
    Sep 23, 2004
  2. Markus
    Replies:
    1
    Views:
    1,108
    Markus
    Nov 22, 2005
  3. Philippe Poulard
    Replies:
    2
    Views:
    363
    Philippe Poulard
    Dec 4, 2003
  4. Ken Philips
    Replies:
    1
    Views:
    350
    Tjerk Wolterink
    Sep 22, 2004
  5. Andrew Chen
    Replies:
    1
    Views:
    199
    David Chelimsky
    Mar 25, 2008
Loading...

Share This Page