Q:

XSL to copy node if certain condition is matched

I have this pseudo-xml:
<?xml version="1.0" encoding="UTF-8"?>
<comtec version="2010">
<query name="rgh/TestNTV/ABC">
    <vars>
        <parameter name="ids">1,2,3,4</parameter>
    </vars>
    <err/>
    <Results>
        <record id="1">
            <column name="id_task">1</column>
            <column name="capabilityCode">FR1</column>
            <column name="ColMiss">miss</column>
            <column name="ColHave"/>
        </record>
        <record id="2">
            <column name="id_task">1</column>
            <column name="capabilityCode">FR2</column>
            <column name="ColMiss"/>
            <column name="ColHave">notmiss</column>
        </record>
        <record id="3">
            <column name="id_task">2</column>
            <column name="capabilityCode">D2</column>
            <column name="ColMiss">miss</column>
            <column name="ColHave"/>
        </record>
        <record id="4">
            <column name="id_task">2</column>
            <column name="capabilityCode">F3</column>
            <column name="ColMiss">miss</column>
            <column name="ColHave"/>
        </record>
        <record id="5">
            <column name="id_task">3</column>
            <column name="capabilityCode">SD21</column>
            <column name="ColMiss"/>
            <column name="ColHave">notmiss</column>
        </record>
        <record id="6">
            <column name="id_task">4</column>
            <column name="capabilityCode">XXX</column>
            <column name="ColMiss">miss</column>
            <column name="ColHave"/>
        </record>
    </Results>
</query>
</comtec>

Desired output:
<Results>
<record id="1">
    <column name="id_task">1</column>
    <column name="capabilityCode">FR1</column>
    <column name="ColMiss">miss</column>
    <column name="ColHave"/>
</record>
<record id="2">
    <column name="id_task">1</column>
    <column name="capabilityCode">FR2</column>
    <column name="ColMiss"/>
    <column name="ColHave">notmiss</column>
</record>
<record id="3">
    <column name="id_task">2</column>
    <column name="capabilityCode">D2</column>
    <column name="ColMiss">miss</column>
    <column name="ColHave"/>
</record>
<record id="4">
    <column name="id_task">2</column>
    <column name="capabilityCode">F3</column>
    <column name="ColMiss">miss</column>
    <column name="ColHave"/>
</record>
<record id="6">
    <column name="id_task">4</column>
    <column name="capabilityCode">XXX</column>
    <column name="ColMiss">miss</column>
    <column name="ColHave"/>
</record>
</Results>

Basically I want to copy every "record" tag for each ID that has "ColMiss" NOT NULL or a combination of ("ColMiss" not null and "ColHave" not null). More exactly, if my id_task is reapeating (as in the example) and it has 2 records one with 'ColMiss" not null and another record with CollMiss null but with ColHave not null i want to copy both "records" for information.
If I have a task that has only "ColMiss" not null then I want to copy all records of that
If I have a task that has only "ColHave" null then I don't want that information.
In other words, if an ID has 'miss' then copy all records for that ID, if an ID doesn't have 'miss' then don't copy.
Someone told me this should be done with variables? 
Thank you very much for your help
UPDATE;
Current XSL
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="@*|node()">
    <comtec>
        <xsl:for-each select="//record">
            <xsl:variable name="var_id2">
                <xsl:value-of select="column[@name='ColMiss']"/>
            </xsl:variable>
            <xsl:variable name="var_id3">
                <xsl:value-of select="column[@name='ColHave']"/>
            </xsl:variable>
            <xsl:if test="($var_id2 !='') ">
                <xsl:variable name="var_id">
                    <xsl:value-of select="column[@name='id_task']"/>
                </xsl:variable>
                <record>
                    <xsl:copy-of select="node()"/>
                </record>
            </xsl:if>
        </xsl:for-each>
    </comtec>
</xsl:template>
</xsl:stylesheet>

This selects all records (but without the attribute "ID" which i need) but it doesn't copy all records for the id_task = 1 in my example, obviously why but i don't know how to go from here to make the expected result.

A:

You don't need variables here, but you could benefit from using a key to look up the record elements by id
<xsl:key name="record" match="record" use="column[@name='id_task']" />

Then it is just a case of selecting record elements where a record in the key for its id has a ColMiss specified.
Try this XSLT
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

<xsl:key name="record" match="record" use="column[@name='id_task']" />

<xsl:template match="@*|node()">
    <comtec>
        <xsl:copy-of select="//record[key('record', column[@name='id_task'])/column[@name='ColMiss'][normalize-space()]]" />
    </comtec>
</xsl:template>
</xsl:stylesheet>

Note that this is not entirely efficient as you will be checking the same node set for every record in that set. Instead you can't make use of a technique called Muenchian grouping, so you only perform the check of ColMiss for the first record in each set
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

<xsl:key name="record" match="record" use="column[@name='id_task']" />

<xsl:template match="@*|node()">
    <comtec>
        <xsl:for-each select="//record
                                [generate-id() = generate-id(key('record', column[@name='id_task'])[1])]
                                [key('record', column[@name='id_task'])/column[@name='ColMiss'][normalize-space()]]">
            <xsl:copy-of select="key('record', column[@name='id_task'])" />
        </xsl:for-each>
    </comtec>
</xsl:template>
</xsl:stylesheet>

