|
Subject: RE: [xsl] Cartesian product of sets of nodes From: Bartolomeo Nicolotti <bnicolotti@xxxxxxxxx> Date: Mon, 31 Aug 2009 09:51:01 +0200 |
Hi,
I thought that the question was syntetic, but clear, and no example was
needed, sorry for misunderstanding.
In the input xml we've hotels with available rooms in respone to a
search criteria from the user, for example for "1 room for 2 people and
1 room for 3 people" one may obtain:
<h>
<r type="double"/> <!-- 2 people onebed-->
<r type="twin"/> <!-- 2 people separated beds-->
<r type="triple/> <!-- 3 people -->
</h>
In this format the rooms amog which one can choose are all together, one
can choose between the two combinations:
<r type="double"/> <!-- 2 people -->
<r type="triple/> <!-- 3 people -->
<r type="twin"/> <!-- 2 people -->
<r type="triple/> <!-- 3 people -->
In the output xml we need to have only the combinations that fits
exactly the user request, so something like
<h>
<r type="double"/> <!-- 2 people -->
<r type="triple/> <!-- 3 people -->
</h>
<h>
<r type="twin"/> <!-- 2 people -->
<r type="triple/> <!-- 3 people -->
</h>
So my idea is to group the rooms by number of people and then do all the
combinations of elements from each group, i.e. something like a
cartesian product.
I think that we can group the nodes fragmets in a variable
$s[1] --> "<r type="double"/> <!-- 2 people -->
<r type="twin"/> <!-- 2 people -->"
$s[2] --><r type="triple/> <!-- 3 people -->
then use a recursive template like this
<template name="combine-rooms">
<param name="rooms">
<for-each select="rooms[1]/room">
<!-- tranlate the single room and output -->
<!-- obtain trailing rooms xml fragments, simples version:-->
<value-of select="rooms[1]/room"/>
<if test="count(rooms)>1">
<variable name="etc-rooms" select="for $x in 2 to last(rooms) return
rooms[$x]"/>
<call-template name="combine-rooms">
<with-param name="rooms" select="$etc-rooms">
</call-template>
</if>
</for-each>
</funtion>
What do you think about this?
Many thanks
Bye
Il giorno ven, 28/08/2009 alle 18.42 +0100, Michael Kay ha scritto:
> > Hi,
> >
> > we've a variable number of sets of nodes of variable
> > carindinality grouped from incoming xml,
> >
> > S1, S2, S3, ... Sn
> >
> > is there a way of obtaining the cartesian product
> >
> > S1 x S2 x S3 x S4 x... Sn
> >
>
> I think it would be useful to explain what you mean by showing the XML input
> and the desired XML output.
>
> My understanding is that "cartesian product" has a mathematical meaning, and
> a conventional usage when talking about the relational model, and they
> aren't the same. One doesn't see the term used much in relation to XML. In
> particular, I'm not sure how you would represent a "variable number of sets
> of nodes" in the XPath data model, unless the nodes all happen to be in the
> same tree.
>
> Regards,
>
> Michael Kay
> http://www.saxonica.com/
> http://twitter.com/michaelhkay
>
--
Bartolomeo Nicolotti
SIAP s.r.l.
www.siapcn.it
v.S.Albano 13 12049
TrinitC (CN) Italy
ph:+39 0172 652553
centralino: +39 0172 652511
fax: +39 0172 652519
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| RE: [xsl] Cartesian product of sets, Michael Kay | Thread | [xsl] How to "flatten" a XML file w, reynaldo . rizzo |
| Re: [xsl] Help on XSL to tranform s, Martin Honnen | Date | [xsl] Extracting data from external, Joga Singh Rawat |
| Month |