使用XSLT动态比较元素

时间:2018-04-16 13:57:23

标签: xslt

我的XML文档如下所示。

<root>
    <Book>
        <Book_title/>
        <author_name/>
    </Book>
    <Book>
        <Book_title/>
        <author_name/>
    </Book>
    <author_details>
        <author_name/>
        <author_DOB/>
    <author_details/>
</root>

我们可以将Book / author_name与author_details / author_name动态地与XSLT进行比较...... ??

1 个答案:

答案 0 :(得分:1)

定义一个键

<xsl:key name="author" match="author_details" use="autor_name"/>

然后为

编写模板
<xsl:template match="Book/author_name">
  <xsl:copy-of select=". | key('author', .)/author_DOB"/>
</xsl:template>

通过身份转换处理rootBook(例如,在XSLT 3中为<xsl:mode on-no-match="shallow-copy"/>)并添加一个空

<xsl:template match="author_details"/>

以防止复制/输出这些元素。

相关问题