[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Problem using Key on multiple elements

Subject: Problem using Key on multiple elements
From: Sreenath Juluri <jssreenath@xxxxxxxxx>
Date: Fri, 12 Aug 2005 18:50:00 +0530
xsl element name select
hi,

My source xml looks something like this.

<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>
<member>
</crew>
<crew program="EP3556823923">
<role>Director</role>
<givenname>Michael</givenname>
<surname>Sinelnikoff</surname>
</member>
<member>
</crew>
<role>Actor</role>
<givenname>Michael</givenname>
<surname>Offer</surname>
</member>
<member>
<role>Executive Producer</role>
<givenname>John</givenname>
<surname>Landis</surname>
</member>
</crew>

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.

So to get unique names i create a key based on givenname and surname as
follows

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

first i tried

<xsl:for-each
select="a:xtvd/a:productionCrew/a:crew/a:member/a:givenname[generate-id(conca
t(.,'+',parent::node()/a:surname))=generate-id(key('roleNames',concat(.,'+',p
arent::node()/a:surname)))]">

but since generate-id expects node-set the abv does not work.

so i create a temp variable as follows.

<xsl:variable name="givenNsurnames">
<rolenames>                                                     <xsl:for-each
select="a:xtvd/a:productionCrew/a:crew/a:member">
                    <xsl:element name="t">
               <xsl:value-of select="concat(a:givenname,'+',a:surname)"/>
            </xsl:element>
</xsl:for-each>
</rolenames>
</xsl:variable>

and try doing

<xsl:for-each
select="exsl:nodeSet($givenNsurnames)/rolenames/t[generate-id()=generate-id(k
ey('roleNames',.))]">

<xsl:element name="n">
   <xsl:attribute name="id"><xsl:value-of
select="generate-id()"/></xsl:attribute>
   <xsl:value-of select="."/>
</xsl:element>

</xsl:for-each>

but the control comes out of for-each. Some how id generated do not
match. Where am i going wrong?
iam new to XML/XSLT...Is there any other work arround or a simpler way
to achieve this?

thnx,
Sreenath.

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.