使用xslt递归删除Heat.exe生成的文件夹

时间:2016-08-26 21:46:17

标签: xml xslt recursion wix heat

我知道有删除单个目录的问题和答案。我有一个由Heat.exe生成的XML,它包含1000个文件和大约20个顶级目录。我想使用xsl转换删除其中一个顶级目录。该目录中有6个目录,这些目录有一些等等。

我的代码只会删除顶级目录(称为测试)和任何自身没有子文件夹的子文件夹,这使我无法解决引用错误:

<?xml version="1.0" ?>
    <xsl:stylesheet version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:wix="http://schemas.microsoft.com/wix/2006/wi">

        <!-- Copy all attributes and elements to the output. -->
        <xsl:template match="@*|*">
            <xsl:copy>
                <xsl:apply-templates select="@*" />
                <xsl:apply-templates select="*" />
            </xsl:copy>
        </xsl:template>

        <xsl:output method="xml" indent="yes" />

        <!-- Create searches for the directories to remove. -->
    	<xsl:key name="tests-search" match="wix:Directory[@Name='tests']//wix:Component" use="@Id" />
<!-- Remove directories. -->
    <xsl:template match="wix:Directory[@Name='tests']" />
<!-- Remove Components referencing those directories. -->
	<xsl:template match="wix:Component[key('tests-search', @Directory)]" />
  <!-- Remove DirectoryRefs (and their parent Fragments) referencing those directories. -->
<xsl:template match="wix:Fragment[wix:DirectoryRef[key('tests-search', @Id)]]" />

如果我将关键线更改为

<xsl:key name="tests-search1" match="wix:Directory[@Name = 'tests']" use="descendant::wix:Component/@Id" /> 

它将删除所有子文件夹的子文件夹,但保留顶级目录中的所有组件(文件)。

如果我同时使用这两个键,它仍然以顶级目录(测试)中的所有组件结束,从而给出了未解决的参考错误。

是否有一种方法或单个搜索键可以递归删除顶级文件夹中的所有文件和子文件夹?

谢谢!

0 个答案:

没有答案
相关问题