Re: [xsl] simplifying the XSL for an intersection

Subject: Re: [xsl] simplifying the XSL for an intersection
From: "leona s" <lrs@xxxxxxxxxxxx>
Date: Wed, 15 Jan 2003 13:56:36 -0600
Joerg,

You are absolutely correct on the first point. 'A' won't be included in the
result set, but that is what I want to have happen in this application. It
did
cause a problem further down in the application, where Items were
being displayed in which player '53' has no Role, but I was able to fix
that.

The expression rewriting works fine and is much easier to read. I know
that including the extra node, Matrix, in every expression is not as
efficient
as your versions, but I'm curious as to how one would measure this.
Obviously,
a small example like this isn't very useful, but as the XML grows it would
be nice to have measurements of execution time.

Thanks very much for the help,
Leona Slepetis

From: "Joerg Heinicke" wrote:


> Hello Leona,
>
> isn't it possible that your requirement gets out of hand? For example I
> add an Item like the following:
>
> <Item iID="1">
>      <RoleLink iRoleID="X"/>
>      <RoleLink iRoleID="A"/>
> </Item>
>
> and a simple Role like the following:
>
> <Role roleID="A">
>      <PlayerLink player="1"/>
>      <PlayerLink player="3"/>
> </Role>
>
> A won't be caught in the first run, but maybe it has to, because it's in
> the same Item as X. It seems that a recursive approach is needed, isn't
it?
>
> Without recursion and not really simpler, but I think more readable and
> easier to understand is the following rewriting:
>
> <xsl:variable name="player" select="53"/>
>
> You can pull the root element <Matrix/> into the variable declaration of
> $matrix. So you avoid to type it always in the expressions below:
> <xsl:variable name="matrix" select="document('matrix.xml')/Matrix"/>
>
> <xsl:variable name="playerroles"
> select="$matrix/Role[PlayerLink/@player=$player]"/>
>
> Your expression was:
> <xsl:variable name="matrixroles"
> select="$matrix/Role[@roleID = $matrix/Item/RoleLink/@iRoleID
> [../../RoleLink/@iRoleID = $playerroles/@roleID]]"/>
>
> rewritten:
> <xsl:variable name="matrixroles"
> select="$matrix/Role[@roleID = $matrix/Item
> [RoleLink/@iRoleID = $playerroles/@roleID]/RoleLink/@iRoleID]"/>
>
> or adding a new variable for further better readability:
>
> <xsl:variable name="items" select="$matrix/Item[RoleLink/@iRoleID =
> $playerroles/@roleID]"/>
> <xsl:variable name="matrixroles"
> select="$matrix/Role[@roleID=$items/RoleLink/@iRoleID]"/>
>
> Does this help a bit? And what about my first comment?
>
> Regards,
>
> Joerg
>
> leona s wrote:
> > Hi All,
> >
> > I am trying to get a set of nodes that is really an intersection
> > and would appreciate some ideas for a solution.
> >
> > What I need is the set of Matrix/Role nodes,
> >   that contains all of Roles for Items
> >   where $player is in at least one of the Roles for that Item.
> >
> > For example, if I have a variable $player = '53', I
> > should get the set of Roles where roleID = {W,X,Y}, because
> > 53 is in W and Y, and although 53 is not in X, that Role
> > is in at least one Item that also has roles W and Y. Also,
> > 53 is in Role Z, but that Role does not belong to any Item so it is not
> > included.
> >
> > I have a solution that works, but I was wondering if there is a simpler
> > way to express this.
> >
> > <xsl:variable name="player" select="53"/>
> > <xsl:variable name="matrix" select="document('matrix.xml')"/>
> > <xsl:variable name="playerroles"
> > select="$matrix/Matrix/Role[PlayerLink/@player=$player]"/>
> > <xsl:variable name="matrixroles"
> >
select="$matrix/Matrix/Role[@roleID=$matrix/Matrix/Item/RoleLink/@iRoleID[..
> > /../RoleLink/@iRoleID=$playerroles/@roleID]]"/>
> >
> > <Matrix>
> >   <Role roleID="W">
> >     <PlayerLink player="1"/>
> >     <PlayerLink player="3"/>
> >     <PlayerLink player="6"/>
> >     <PlayerLink player="53"/>
> >   </Role>
> >   <Role roleID="X">
> >     <PlayerLink player="1"/>
> >     <PlayerLink player="3"/>
> >   </Role>
> >   <Role roleID="Y">
> >     <PlayerLink player="1"/>
> >     <PlayerLink player="3"/>
> >     <PlayerLink player="51"/>
> >     <PlayerLink player="53"/>
> >   </Role>
> >   <Role roleID="Z">
> >     <PlayerLink player="3"/>
> >     <PlayerLink player="53"/>
> >   </Role>
> >
> >   <Item iID="123">
> >     <RoleLink iRoleID="W"/>
> >     <RoleLink iRoleID="X"/>
> >     <RoleLink iRoleID="Y"/>
> >   </Item>
> >
> >   <Item iID="456">
> >     <RoleLink iRoleID="X"/>
> >     <RoleLink iRoleID="Y"/>
> >   </Item>
> >
> >   <Item iID="789">
> >     <RoleLink kgRoleID="Y"/>
> >   </Item>
> > </Matrix>
> >
> > Thanks very much,
> > Leona Slepetis
> > lrs@xxxxxxxxxxxx
>
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>
>



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread