|
Subject: [xsl] Problem using Key on multiple elements From: Sreenath Juluri <jssreenath@xxxxxxxxx> Date: Fri, 12 Aug 2005 18:50:00 +0530 |
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 |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] problems with position() , Georges Schmitz | Thread | Re: [xsl] Problem using Key on mult, Joris Gillis |
| Re: [xsl] problems with position() , Georges Schmitz | Date | [xsl] Breaking from the loop (for-e, Oleg Konovalov |
| Month |