user9324800
user9324800

Reputation: 163

XSLT template match filter

I'm able to use below XSLT to transform the XML which is returning expected output.

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>

Output

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

Question: I'm trying to transform the xml into desired xml using xslt. Can anyone help with xslt transformation. If I wanted to get the output as below, how should I modify the XSLT ?

Question: I'm trying to transform the xml into desired xml using xslt. Can anyone help with xslt transformation. If I wanted to get the output as below, how should I modify the XSLT ?

Question: I'm trying to transform the xml into desired xml using xslt. Can anyone help with xslt transformation. If I wanted to get the output as below, how should I modify the XSLT ?

Question: I'm trying to transform the xml into desired xml using xslt. Can anyone help with xslt transformation. If I wanted to get the output as below, how should I modify the XSLT ?

Desired Output

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

Upvotes: 2

Views: 197

Answers (2)

Siebe Jongebloed
Siebe Jongebloed

Reputation: 4870

Then use this:

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

Upvotes: 1

Bert Verhees
Bert Verhees

Reputation: 1063

Try writing your template line like this.

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

Upvotes: 0

Related Questions