Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Re: XSLT: from 2 elements to 1

Reply
Thread Tools

Re: XSLT: from 2 elements to 1

 
 
Will Stuyvesant
Guest
Posts: n/a
 
      07-15-2003
> [Dimitre Novatchev}
> Sory, but there's no XML in your example.
>
> Can you provide the minimal possible example (xml source document
> explained, the desired properties of the transformation, the exact
> desired result) ?



Just about the simplest example I can think of:

According to the derivation rule

P and P
-------
P

I am looking for XSLT that transforms

<math xmlns="http://www.w3.org/1998/Math/MathML">
<apply>
<and/>
<ci>P</ci> <!-- (1) -->
<ci>P</ci> <!-- (2) -->
</apply>
</math>

into:

<math xmlns="http://www.w3.org/1998/Math/MathML">
<ci>P</ci>
</math>

The comments can be ignored.

Note that the transformation should also work for more
complicated MathML expressions than just <ci>P</ci>. If
that is the case, the XSLT has to check whether the same
XML tree is in positions (1) and (2).

Perhaps XSLT is just not suitable for these kind of
templated transformations. But somewhere on usenet I read
that XSLT "constains a theorem prover in itself" so I
thought perhaps we can reuse that.
 
Reply With Quote
 
 
 
 
Dimitre Novatchev
Guest
Posts: n/a
 
      07-16-2003

"Will Stuyvesant" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> > > [Will]
> > > Just about the simplest example I can think of:
> > >
> > > According to the derivation rule
> > >
> > > P and P
> > > -------
> > > P

> >
> > [Dimitre Novatchev]
> > And how will you represent in xml the above rule?
> >
> > This is not nit-picking, but very important question -- very much

depends on
> > its answer. Hint: you must somehow specify that the two arguments of

"and"
> > are identical.
> >

>
> Indeed this is a core part of the problem. I don't know how to
> represent this derivation rule in XSLT, that is why I started this
> thread!


Not in XSLT -- you do not know how to represent the rule in XML. XSLT is
XML.

Therefore this is not (yet) an XSLT problem. XSLT starts when given the
source xml (or an equivalent tree) and the description of the properties of
the transformation.

I have some ideas about a possible transformation, but they can be
implemented only after you propose an XML representation of the rule.


=====
Cheers,

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



>
> We are now looking at another solution, representing the above rule in
> an extended MathML and using a tool we are developing. We need to
> bind attribute values and tag names to tool program variables, and be
> able to use these variables for matching and output. This way an XML
> tree can be created that can be matched with the input. But a lot of
> work has still to be done. To get an idea how the rule is represented
> in XML:
>
> <rule>
> <antecedent>
> <ws-tree bind="A"/>
> <apply>
> <and/>
> <ws-tree bind="B"/>
> <ws-tree use="B"/>
> </apply>
> <ws-tree bind="C"/>
> </antecedent>
> <consequence>
> <ws-tree use="A"/>
> <ws-tree use="B"/>
> <ws-tree use="C"/>
> </consequence>
> </rule>
>
>
> The elements "rule", "antecedent", "consequence" and "ws-tree" are an
> extension to MathML.
>
> The tool applying this rule to the input (in an earlier post), tries
> to match the input with the antecedent of the rule. When the tool
> sees a "ws-tree" element with a bind attribute, it binds the element
> at that point in the input to a variable in program memory that takes
> as name the value of attribute "bind". When there is a ws-tree with a
> "use" attribute the tool checks whether the input indeed has that tree
> at that position in the input.
>
> If the input matches then the XML output can be created according to
> the consequence of the rule.
>
> There will be more elements like "ws-tree" needed, this is still
> research.



 
Reply With Quote
 
 
 
 
Dimitre Novatchev
Guest
Posts: n/a
 
      07-17-2003

"Will Stuyvesant" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> [Dimitre Novatchev]
> > Therefore this is not (yet) an XSLT problem. XSLT starts when given the
> > source xml (or an equivalent tree) and the description of the properties

of
> > the transformation.
> >
> > I have some ideas about a possible transformation, but they can be
> > implemented only after you propose an XML representation of the rule.

>
> But, in the original post there is an example and later I also added a
> rule encoded in XML (used by a template mechanism different from
> XSLT). As shown, in the simplest case only the elements <rule>,
> <antecedent> (rule input) and <consequence> (rule output) are needed.
> The rule itself should also be clear, if you have ever seen derivation
> rules in logic or mathematics, and even if you did not, you can
> imagine all the kind of rules that could be useful. What else do you
> need??


There must be something expressing the important property that the two
arguments of "and" are equal (identical) and that this should be regarded as
important by the problem solver. This generally cannot be inferrred
automatically.

>
> Perhaps you can answer this one:
>
> How can I transform
>
> <container>
> <item number="1"/>
> <item number="1"/>
> </container>
>
> to
>
> <item number="1"/>
>
> ?
>
> That would be
>
> <xsl:template match="?????">
> <item number="1"/>
> </xsl:template>


Yes, but it will not work in the general case:

<xsl:template match="container[*[1][self::item and @number="1"]
and
*[2][self::item and
@number="1"]
and
not(*[3])
]">
<item number="1"/>
</xsl:template>



>
> so the problem is the ????? And I can't find this in the (XPath)
> docs.
>
> I did some stuff with XSLT but I have no idea how to do something like
> "remember a subtree in a variable" and then later matching against it.


If the rule can express the essential properties, the transformation will
not be too problematic.


Another question is when the inference process will eventually stop? All the
rules can be tried and applied on the result, then on the next result, and
so on... potentially never stopping. There must be some rules about this as
well.


=====
Cheers,

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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
XSLT: iterating all child elements and accessing homonymous childrenin sibling elements Gerald Aichholzer XML 2 06-27-2006 03:46 PM
How do I allow both elements or No elements Billy XML 4 09-12-2005 08:29 AM
Elements within elements Jyrki Keisala XML 5 06-15-2005 04:58 PM
container elements for repeating elements ('element farms') needed? Wolfgang Lipp XML 1 01-30-2004 04:09 PM
container elements for repeating elements ('element farms') needed? Wolfgang Lipp XML 0 01-28-2004 02:50 PM



Advertisments