Subject: [xsl] Multiple conditions in single key statement From: "Ganesh Babu N" <nbabuganesh@xxxxxxxxx> Date: Mon, 15 Sep 2008 21:32:18 +0530 |
Dear All, Is it possible to define a key element with union of two different conditions? My requirement is as follows: XML: Two D structures are in the same file. <D AN="0019053-200826080-00002" V="2000.3F" FILE="G0019053-200826080-00002"> <BB> <BY> <PN ILINK="1" ITYPE="sp"> <FN>Joep</FN><SN>Damen</SN> </PN> <PN ILINK="2" ITYPE="sp"> <FN>Sue</FN><SN>Caleo</SN> </PN> <AF> <P> <SP>1</SP> Pharmerit BV, Rotterdam, the Netherlands</P> <P> <SP>2</SP> Janssen Pharmaceutica NV, Beerse, Belgium</P> </AF> </BY> </BB> </D> <D AN="0019053-200826080-00004" V="2000.3F" FILE="G0019053-200826080-00004"> <BB> <BY> <PN ILINK="1" ITYPE="sp"> <FN>Emily</FN> <SN>Lancsar</SN></PN> <PN ILINK="2" ITYPE="sp"> <FN>Jordan</FN> <SN>Louviere</SN></PN> <AF> <P> <SP>1</SP> Business School (Economics) and Institute of Health and Society, University of Newcastle upon Tyne, Newcastle upon Tyne, UK</P> <P> <SP>2</SP> Centre for the Study of Choice, University of Technology, Sydney, New South Wales, Australia</P></AF> </BY> </BB> </D> The desired output is: Author-Name: Joep Damen Author-Name-First: Joep Author-Name-Last: Damen Author-Workplace-Name: Pharmerit BV, Rotterdam, the Netherlands Author-Name: Sue Caleo Author-Name-First: Sue Author-Name-Last: Caleo Author-Workplace-Name: Janssen Pharmaceutica NV, Beerse, Belgium Author-Name: Emily Lancsar Author-Name-First: Emily Author-Name-Last: Lancsar Author-Workplace-Name: Business School (Economics) and Institute of Health and Society, University of Newcastle upon Tyne, Newcastle upon Tyne, UK Author-Name: Jordan Louviere Author-Name-First: Jordan Author-Name-Last: Louviere Author-Workplace-Name: Centre for the Study of Choice, University of Technology, Sydney, New South Wales, Australia My XSLT: <xsl:key name="affid" match="D/BB/BY/AF/P" use="SP"/> <xsl:template match="PN"> <xsl:choose> <xsl:when test="@ILINK"> Author-Name: <xsl:value-of select="FN"/><xsl:text> </xsl:text><xsl:if test="MN"><xsl:value-of select="MN"/>. </xsl:if><xsl:value-of select="SN"/> <xsl:apply-templates/> <xsl:variable name="affk" select="key('affid',@ILINK])"/> <xsl:value-of select="$affk"/> </xsl:when> </xsl:chose> </xsl:template> But I am getting the output as follows: Author-Name: Joep Damen Author-Name-First: Joep Author-Name-Last: Damen Author-Workplace-Name: 1 Pharmerit BV, Rotterdam, the Netherlands Author-Workplace-Name: 1 Business School (Economics) and Institute of Health and Society, University of Newcastle upon Tyne, Newcastle upon Tyne, UK Author-Name: Sue Caleo Author-Name-First: Sue Author-Name-Last: Caleo Author-Workplace-Name: 2 Janssen Pharmaceutica NV, Beerse, Belgium Author-Workplace-Name: 2 Centre for the Study of Choice, University of Technology, Sydney, New South Wales, Australia Author-Name: Emily Lancsar Author-Name-First: Emily Author-Name-Last: Lancsar Author-Workplace-Name: 1 Pharmerit BV, Rotterdam, the Netherlands Author-Workplace-Name: 1 Business School (Economics) and Institute of Health and Society, University of Newcastle upon Tyne, Newcastle upon Tyne, UK Author-Name: Jordan Louviere Author-Name-First: Jordan Author-Name-Last: Louviere Author-Workplace-Name: 2 Janssen Pharmaceutica NV, Beerse, Belgium Author-Workplace-Name: 2 Centre for the Study of Choice, University of Technology, Sydney, New South Wales, Australia As per the logic of the key element this output is correct. But it is not my desired format. The only way of differentiation is @AN in the D element. So in the key element is it possible to include union of two conditions such as use="concat(@AN, SP) " to check with key('affkey', concat(@AN, @ILINK)). Please suggest the above will give the result or any better solution for this case. Regards, Ganesh
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Tag movement in XML, Ganesh Babu N | Thread | Re: [xsl] Multiple conditions in si, David Carlisle |
Re: [xsl] Tag movement in XML, David Carlisle | Date | Re: [xsl] Multiple conditions in si, David Carlisle |
Month |