如何将'affiliation'元素移动到XSLT中'for-each'上下文中的'contrib'元素中?如何将元素移动到XSLT中的另一个变换元素中?
输入XML:
<article>
<authors>Amrendra, Kumar; Mohan, Kumar</authors>
<affiliation id="Amrendra, Kumar">Amrendra, Kumar</affiliation>
<affiliation id="Mohan, Kumar">Mohan, Kumar</affiliation>
</article>
电流输出:
<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代码:
<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>
所需的输出:(带AFF/@ ID和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>
当我尝试应用里面的contrib“归属”元素,则其显示如下错误:
[Saxon-PE 9.5.1.7] XPTY0020: Cannot select the parent of the context node: the context item is not a node
你能证明你的演示问题,请完整的XSLT?我不认为所显示的模板会导致错误,除非您的实际XSLT在'xsl:for-each'结构中具有' ',不是在它之后。谢谢。 –
作者和相应的“隶属关系”之间有什么联系?你在3个地方有相同的值,很难说出哪一对要用。 –