gpt4 book ai didi

xml - 将xml标签名提取为xml属性值

转载 作者:行者123 更新时间:2023-12-03 16:12:35 26 4
gpt4 key购买 nike

示例 xml 文件如下所示

<a>
<apple color="red"/>
</a>

我应该用 XSLT 写什么才能得到 样本输出 以下 ?
<AAA>
<BB bbb="#apple"/> <!-- if possible make it auto close -->
</AAA>

最佳答案

使用 name() local-name() 职能:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>

<xsl:template match="/a">
<AAA>
<xsl:apply-templates/>
</AAA>
</xsl:template>

<xsl:template match="*">
<BB bbb="{concat('#', name())}"/>
</xsl:template>

</xsl:stylesheet>

关于xml - 将xml标签名提取为xml属性值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8564481/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com