XSLT 模板匹配过滤器

XSLT template match filter

我可以使用下面的 XSLT 来转换返回预期输出的 XML。

XML

<?xml version='1.0' encoding='UTF-8'?>
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
    <env:Body>
        <cc1:Get_Items_Response xmlns:cc1="urn:com.test/123" cc1:version="v1.0">
            
            <cc1:Response_Data>
                <cc1:Item>
                    <cc1:Item_Reference>
                        <cc1:ID cc1:type="Item_ID">12345</cc1:ID>
                    </cc1:Item_Reference>
                    <cc1:Item_Data>
                        <cc1:Item_ID>12345</cc1:Item_ID>                                                                    
                        
                        <cc1:Item_Classification_Data>
                            <cc1:Item_Classification_Reference>AAA</cc1:Item_Classification_Reference>
                            <cc1:Item_Classification_Field_Interface_Data>123</cc1:Item_Classification_Field_Interface_Data>
                        </cc1:Item_Classification_Data>
                        
                        <cc1:Item_Classification_Data>
                            <cc1:Item_Classification_Reference>BBB</cc1:Item_Classification_Reference>
                            <cc1:Item_Classification_Field_Interface_Data>456</cc1:Item_Classification_Field_Interface_Data>
                        </cc1:Item_Classification_Data>                                              
                        
                        
                    </cc1:Item_Data>
                </cc1:Item>
            </cc1:Response_Data>
        </cc1:Get_Items_Response>
    </env:Body>
</env:Envelope>

XSLT

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:cc1="urn:com.test/123" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">    
    
    <xsl:template match="cc1:Get_Items_Response/cc1:Response_Data/cc1:Item/cc1:Item_Data/cc1:Item_Classification_Data">
        <!-- Do nothing -->
    </xsl:template>    
    
    
    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template> 
</xsl:stylesheet>

输出

<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
    <env:Body>
        <cc1:Get_Items_Response xmlns:cc1="urn:com.test/123" cc1:version="v1.0">

            <cc1:Response_Data>
                <cc1:Item>
                    <cc1:Item_Reference>
                        <cc1:ID cc1:type="Item_ID">12345</cc1:ID>
                    </cc1:Item_Reference>
                    <cc1:Item_Data>
                        <cc1:Item_ID>12345</cc1:Item_ID>
                    </cc1:Item_Data>
                </cc1:Item>
            </cc1:Response_Data>
        </cc1:Get_Items_Response>
    </env:Body>
</env:Envelope>

问题:我正在尝试使用 xslt 将 xml 转换为所需的 xml。任何人都可以帮助进行 xslt 转换。如果我想获得如下输出,我应该如何修改 XSLT?

问题:我正在尝试使用 xslt 将 xml 转换为所需的 xml。任何人都可以帮助进行 xslt 转换。如果我想获得如下输出,我应该如何修改 XSLT?

问题:我正在尝试使用 xslt 将 xml 转换为所需的 xml。任何人都可以帮助进行 xslt 转换。如果我想获得如下输出,我应该如何修改 XSLT?

问题:我正在尝试使用 xslt 将 xml 转换为所需的 xml。任何人都可以帮助进行 xslt 转换。如果我想获得如下输出,我应该如何修改 XSLT?

期望输出

<?xml version='1.0' encoding='UTF-8'?>
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
    <env:Body>
        <cc1:Get_Items_Response xmlns:cc1="urn:com.test/123" cc1:version="v1.0">
            
            <cc1:Response_Data>
                <cc1:Item>
                    <cc1:Item_Reference>
                        <cc1:ID cc1:type="Item_ID">12345</cc1:ID>
                    </cc1:Item_Reference>
                    <cc1:Item_Data>
                        <cc1:Item_ID>12345</cc1:Item_ID>                                                                    
                        
                        <cc1:Item_Classification_Data>
                            <cc1:Item_Classification_Reference>AAA</cc1:Item_Classification_Reference>
                            <cc1:Item_Classification_Field_Interface_Data>123</cc1:Item_Classification_Field_Interface_Data>
                        </cc1:Item_Classification_Data>                                                                                             
                        
                    </cc1:Item_Data>
                </cc1:Item>
            </cc1:Response_Data>
        </cc1:Get_Items_Response>
    </env:Body>
</env:Envelope>

试着像这样写你的模板行。

<xsl:template match="cc1:Get_Items_Response/cc1:Response_Data/cc1:Item/cc1:Item_Data/cc1:Item_Classification_Data[text()='BBB']">
    <!-- Do nothing -->
</xsl:template>    

然后使用这个:

<xsl:template match="cc1:Item_Classification_Data[cc1:Item_Classification_Reference[text()='BBB']]">
    <!-- Do nothing -->
</xsl:template>