如何使用当前属性值重写元素的属性值?
How to rewrite an element's attribute value using the current attribute value?
我有一个几乎可以工作的 XSLT 示例,但出于某种原因,它将属性添加到父级而不是重写我试图重写的节点。
输入XML
<Include xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Fragment>
<DirectoryRef Id="WEBFOLDER">
<Directory Id="dirA82847423D2E0E6780E69FEDB5941AC0" Name="web">
<Component Id="cmpADE52C2B19915F5AFB7C41166996B6C5" Guid="*">
<File Id="fil83688EC53AE556DE24B5F5444F16F6BE" KeyPath="yes" Source="$(var.SolutionDir)\Company.PCR.Blazor.dll" />
</Component>
</Directory>
</DirectoryRef>
</Fragment>
</Include>
我的 XSL(转换)
<!-- patch relative paths -->
<xsl:template match="wix:File">
<xsl:attribute name="Source">
<xsl:value-of select="concat(substring(self::node()/@Source,0,19), '..\artifacts\msi\web\', substring(self::node()/@Source, 20))"/>
</xsl:attribute>
</xsl:template>
实际输出(当前转换)
<Include xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Fragment>
<DirectoryRef Id="WEBFOLDER">
<Directory Id="dirA82847423D2E0E6780E69FEDB5941AC0" Name="web">
<Component Id="cmpADE52C2B19915F5AFB7C41166996B6C5" Guid="*" Source="$(var.SolutionDir)..\artifacts\msi\web\Company.PCR.Blazor.dll"/>
</Directory>
</DirectoryRef>
</Fragment>
</Include>
预期 XML 输出(已转换):
<Include xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Fragment>
<DirectoryRef Id="WEBFOLDER">
<Directory Id="dirA82847423D2E0E6780E69FEDB5941AC0" Name="web">
<Component Id="cmpADE52C2B19915F5AFB7C41166996B6C5" Guid="*">
<File Id="fil83688EC53AE556DE24B5F5444F16F6BE" KeyPath="yes" Source="$(var.SolutionDir)..\artifacts\msi\web\Company.PCR.Blazor.dll" />
</Component>
</Directory>
</DirectoryRef>
</Fragment>
</Include>
您能解释一下为什么我的 match="wix:File"
将其属性更改应用于其父项吗?
如果要修改Source
属性,那为什么不让模板匹配Source
属性呢?
<xsl:template match="wix:File/@Source">
<xsl:attribute name="Source">
<xsl:value-of select="concat(substring(., 1, 18), '..\artifacts\msi\web\', substring(., 20))"/>
</xsl:attribute>
</xsl:template>
我有一个几乎可以工作的 XSLT 示例,但出于某种原因,它将属性添加到父级而不是重写我试图重写的节点。
输入XML
<Include xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Fragment>
<DirectoryRef Id="WEBFOLDER">
<Directory Id="dirA82847423D2E0E6780E69FEDB5941AC0" Name="web">
<Component Id="cmpADE52C2B19915F5AFB7C41166996B6C5" Guid="*">
<File Id="fil83688EC53AE556DE24B5F5444F16F6BE" KeyPath="yes" Source="$(var.SolutionDir)\Company.PCR.Blazor.dll" />
</Component>
</Directory>
</DirectoryRef>
</Fragment>
</Include>
我的 XSL(转换)
<!-- patch relative paths -->
<xsl:template match="wix:File">
<xsl:attribute name="Source">
<xsl:value-of select="concat(substring(self::node()/@Source,0,19), '..\artifacts\msi\web\', substring(self::node()/@Source, 20))"/>
</xsl:attribute>
</xsl:template>
实际输出(当前转换)
<Include xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Fragment>
<DirectoryRef Id="WEBFOLDER">
<Directory Id="dirA82847423D2E0E6780E69FEDB5941AC0" Name="web">
<Component Id="cmpADE52C2B19915F5AFB7C41166996B6C5" Guid="*" Source="$(var.SolutionDir)..\artifacts\msi\web\Company.PCR.Blazor.dll"/>
</Directory>
</DirectoryRef>
</Fragment>
</Include>
预期 XML 输出(已转换):
<Include xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Fragment>
<DirectoryRef Id="WEBFOLDER">
<Directory Id="dirA82847423D2E0E6780E69FEDB5941AC0" Name="web">
<Component Id="cmpADE52C2B19915F5AFB7C41166996B6C5" Guid="*">
<File Id="fil83688EC53AE556DE24B5F5444F16F6BE" KeyPath="yes" Source="$(var.SolutionDir)..\artifacts\msi\web\Company.PCR.Blazor.dll" />
</Component>
</Directory>
</DirectoryRef>
</Fragment>
</Include>
您能解释一下为什么我的 match="wix:File"
将其属性更改应用于其父项吗?
如果要修改Source
属性,那为什么不让模板匹配Source
属性呢?
<xsl:template match="wix:File/@Source">
<xsl:attribute name="Source">
<xsl:value-of select="concat(substring(., 1, 18), '..\artifacts\msi\web\', substring(., 20))"/>
</xsl:attribute>
</xsl:template>