How to move 'affiliation' element into 'contrib' element which is in 'for-each' context in XSLT?
Input XML:
<article>
<authors>Amrendra, Kumar; Mohan, Kumar</authors>
<affiliation id="Amrendra, Kumar">Amrendra, Kumar</affiliation>
<affiliation id="Mohan, Kumar">Mohan, Kumar</affiliation>
</article>
Current output:
<contrib-group>
<contrib>
<string-name>Amrendra, Kumar</string-name>
</contrib>
<contrib>
<string-name>Mohan, Kumar</string-name>
</contrib>
<aff id="Amrendra, Kumar">Amrendra, Kumar</aff>
<aff id="Mohan, Kumar">Mohan, Kumar</aff>
</contrib-group>
XSLT Code:
<xsl:template match="authors">
<xsl:choose>
<xsl:when test="not(node())"/>
<xsl:otherwise>
<contrib-group>
<xsl:for-each select="tokenize(., ';')">
<contrib>
<string-name>
<xsl:value-of select="normalize-space(.)"/>
</string-name>
</contrib>
</xsl:for-each>
<xsl:apply-templates select="../affiliation"/>
</contrib-group>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
Required Output: (Matching with aff/@id and contrib/#pcdata)
<contrib-group>
<contrib>
<string-name>Amrendra, Kumar</string-name>
<aff id="Amrendra, Kumar">Amrendra, Kumar</aff>
</contrib>
<contrib>
<string-name>Mohan, Kumar</string-name>
<aff id="Mohan, Kumar">Mohan, Kumar</aff>
</contrib>
</contrib-group>
when i try to apply 'affiliation' element inside contrib then it is showing below error:
[Saxon-PE 9.5.1.7] XPTY0020: Cannot select the parent of the context node: the context item is not a node
<xsl:apply-templates select="../affiliation"/>
within thexsl:for-each
structure, not after it. Thank you. – Tim Caffiliation
? You have identical values in 3 places, it's hard to tell which pair to use. – michael.hor257k