views:

64

answers:

2
A: 

This is REALLY quick and untested but you want the selector attribute to not be equal to a value:

<xsl:template match="node()[!@Id='BEED24F05AB78FB588F61D4092654B6D']">
  <xsl:copy><xsl:apply-templates/></xsl:copy>
</xsl:template>

<xsl:template match="frag"/>

<xsl:template match="@*|node()|processing-instruction()|comment()">
  <xsl:copy>
    <xsl:apply-templates
      select="@*|node()|processing-instruction()|comment()"/>
  </xsl:copy>
</xsl:template>

</xsl:stylesheet>
Mark Schultheiss
Mark, I will try in the morning. Its 2:15am and I am calling it quits for tonight. I updated the question with some more detail...in any case thanks for giving up some of your time..
ozczecho
`node()|processing-instruction()|comment()` is redundant. `node()` matches all node types - text nodes, elements, processing instructions, and comments. The only thing it doesn't match are attributes, which aren't nodes, which is why the pattern to match everything is `@*|node()`.
Robert Rossney
@Mark Schultheiss: negation in XPath is `not()` function. In this case you could use "not equal" operator `!=`. Also, with your stylesheet you are saying: "copy everything (even nodes without this @Id) but `frag` elements". So, the result is nothing in this case.
Alejandro
@Robert Rossney - thanks for pointing that out. @Alejando, thanks for that, I knew I was posting this too fast :(
Mark Schultheiss
+2  A: 

This transformation:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
 <xsl:output omit-xml-declaration="yes" indent="yes"/>
 <xsl:strip-space elements="*"/>

 <xsl:template match="node()|@*">
  <xsl:copy>
   <xsl:apply-templates select="node()|@*"/>
  </xsl:copy>
 </xsl:template>

 <xsl:template match="Com[FileName/@Source='My.Exe']"/>

 <xsl:template match="CompRef[@Id=/*/*/*/Com[FileName/@Source='My.Exe']/@Id]"/>

</xsl:stylesheet>

when applied on the provided XML document (corrected to be made well-formed):

<Frags>
    <Frag>
        <DirRef Id="BeemzDir">
            <Com Id="BEED24F05AB78FB588F61D4092654B6D" Guid="{A11AB356-2F45-4157-92EF-ED49F5BE0F70}">
                <FileName Id="fil1" KeyPath="yes" Source="My.Exe" />
            </Com>
            <Com Id="FFF24F05AB78FB588F61D4092654CCC" Guid="{A11AB356-2F45-4157-92EF-ED49F5BE0F70}">
                <FileName Id="fil2" KeyPath="yes" Source="My.Dll" />
            </Com>
        </DirRef>
    </Frag>
    <Frag>
        <ComGroup Id="MyGroup">
            <CompRef Id="BEED24F05AB78FB588F61D4092654B6D" />
            <CompRef Id="FFF24F05AB78FB588F61D4092654CCC" />
        </ComGroup>
    </Frag>
</Frags>

produces the wanted, correct output:

<Frags>
    <Frag>
        <DirRef Id="BeemzDir">
            <Com Id="FFF24F05AB78FB588F61D4092654CCC" Guid="{A11AB356-2F45-4157-92EF-ED49F5BE0F70}">
                <FileName Id="fil2" KeyPath="yes" Source="My.Dll"/>
            </Com>
        </DirRef>
    </Frag>
    <Frag>
        <ComGroup Id="MyGroup">
            <CompRef Id="FFF24F05AB78FB588F61D4092654CCC"/>
        </ComGroup>
    </Frag>
</Frags>
Dimitre Novatchev
@Dimitre: Good one! Also, You could add one stylesheet with `xsl:key`, as there is cross references.
Alejandro
@Alejandro: Sure, I hope I'll find time this evening.
Dimitre Novatchev
Genius...thank you.
ozczecho