使用 XSL 提取 XML 文件的子集 [英] Extract a subset of XML file using XSL

查看:35
本文介绍了使用 XSL 提取 XML 文件的子集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个 XML 文件:

I have this XML file:

<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"标签,这是我不想要的.

My current XSL file is including also "ResponseParameters" tag, which I do not want.

注意节点 className 是动态的.我不知道运行时这个名字会是什么.

<?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 文档),应该避免.

这篇关于使用 XSL 提取 XML 文件的子集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆