xsl-list
[Top] [All Lists]

Re: Problem using Key on multiple elements

2005-08-16 00:58:45
hi Joris Gillis!

Thnx. It works. but i didnot understand the funda....

What i understand is this. generate-id() will create a unique id based
on the current value of the context node. U suggested doing this

<xsl:for-each select="a:xtvd/a:productionCrew/a:crew/a:member
        [generate-id()=generate-id(key('roleNames',
                concat(a:givenname,'+',a:surname))[1])]
        /a:givenname">

In my source xml a:member has 3 elements role, givenname and surname.
In the abv for-each we are generating an id for a:member(with 3
elements) and comparing the same with the id for 
concat(a:givenname,'+',a:surname) in the key roleNames.
I did not understand how both the ids match? can u plz explain me
this...hopefully this shud explain where i went wrong in my original
approach.

Thnx
Sreenath.


On 8/13/05, Joris Gillis <roac(_at_)pandora(_dot_)be> wrote:
Hi,
Tempore 15:20:00, die 08/12/2005 AD, hinc in 
xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com scripsit Sreenath Juluri 
<jssreenath(_at_)gmail(_dot_)com>:

My source xml looks something like this.
... Ill-formed XML

An attempt to construct well-formed XML out of it (please correct the 
namespace)
<xtvd xmlns="a">
<productionCrew>
<crew program="EP3297910048">
<member>
       <role>Actor</role>
       <givenname>Peter</givenname>
       <surname>McCauley</surname>
</member>
<member>
       <role>Actor</role>
       <givenname>Michael</givenname>
       <surname>Sinelnikoff</surname>
</member>
</crew>
<crew program="EP3556823923">
<member>
       <role>Director</role>
       <givenname>Michael</givenname>
       <surname>Sinelnikoff</surname>
</member>
<member>
       <role>Actor</role>
       <givenname>Michael</givenname>
       <surname>Offer</surname>
</member>
<member>
       <role>Executive Producer</role>
       <givenname>John</givenname>
       <surname>Landis</surname>
</member>
</crew>
</productionCrew>
</xtvd>

Now in my transformed xml there should be only one element for each
person irrespective of the role. for eg in the above piece of xml
there shud b only one element for Michael Sinelnikoff.

Try using a key like this:

<xsl:key name="roleNames"
match="a:xtvd/a:productionCrew/a:crew/a:member"
use="concat(a:givenname,'+',a:surname)"/>

and a loop like this:
<xsl:for-each select="a:xtvd/a:productionCrew/a:crew/a:member
       [generate-id()=generate-id(key('roleNames',
               concat(a:givenname,'+',a:surname))[1])]
       /a:givenname">
</xsl:for-each>

regards,
--
Joris Gillis (http://users.telenet.be/root-jg/me.html)
«Η αλήθεια και το λάδι πάντα βγαίνουν από πάνω»

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--


<Prev in Thread] Current Thread [Next in Thread>