如何將'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個地方有相同的值,很難說出哪一對要用。 –