gpt4 book ai didi

xml - 使用 XSL 提取 XML 文件的子集

转载 作者:数据小太阳 更新时间:2023-10-29 01:43:07 26 4
gpt4 key购买 nike

我有这个 XML 文件:

<Response>
<errorCode>error Code</errorCode>
<errorMessage>msg</errorMessage>
<ResponseParameters>
<className>
<attribute1>a</attribute1>
<attribute2>b</attribute2>
</className>
</ResponseParameters>
</Response>

我希望输出为:

<className>
<attribute1>a</attribute1>
<attribute2>b</attribute2>
</className>

我当前的 XSL 文件还包含我不想要的“ResponseParameters”标签。

编辑:注意节点类名是动态的。我不知道这个名称在运行时会是什么。

<?xml version="1.0"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

<xsl:output indent="yes" />

<xsl:template match="/">
<xsl:copy-of select="//ResponseParameters">
</xsl:copy-of>
</xsl:template>
</xsl:stylesheet>

最佳答案

使用:

<xsl:copy-of select="/Response/ResponseParameters/node()"/>

"//" 缩写非常昂贵(导致扫描完整的 XML 文档),应该避免

关于xml - 使用 XSL 提取 XML 文件的子集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/586631/

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