使用XSL提取XML文件的子集

使用XSL提取XML文件的子集,xml,xslt,Xml,Xslt,我有一个XML文件: <Response> <errorCode>error Code</errorCode> <errorMessage>msg</errorMessage> <ResponseParameters> <className> <attribute1>a</attribute1> <

我有一个XML文件:

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

错误代码
味精
A.
B
我希望输出是:

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

A.
B
我当前的XSL文件还包含“ResponseParameters”标记,我不希望这样

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

<?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>

一种方法是将包含节点名称的参数传递到XSLT中,并使用name()函数传递的参数匹配动态节点

编辑:

但在这个简单的例子中,建议ResponseParameters/*或ResponseParameters/*的其他答案都是一个简单得多的解决方案。


<xsl:copy-of select="Response/ResponseParameters//*"/>
使用

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

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