如何在我的 xslt 文件中使用 ends-with 函数
How to use ends-with function in my xslt file
我有这个 wix (.wxs) 文件示例:
<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Fragment>
<DirectoryRef Id="INSTALLLOCATION">
<Component Id="cmpE48528C4F5932A4EFD89F7331108F45D" Guid="*">
<File Id="filF1B84C2C6BCC693224B7A7959445B74F" KeyPath="yes" Source="$(var.SourceDir)\MyFont.ttf" />
</Component>
<Component Id="cmpE48528C4F5932A4EFD89F7331108F45D" Guid="*">
<File Id="filF1B84C2C6BCC693224B7A7959445B74F" KeyPath="yes" Source="$(var.SourceDir)\Newtonsoft.Json.dll" />
</Component>
</DirectoryRef>
</Fragment>
</Wix>
现在我想将属性 TrueType="yes"
添加到 Source 以 'ttf' 结尾的所有文件元素。
所以它应该是这样的:
<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Fragment>
<DirectoryRef Id="INSTALLLOCATION">
<Component Id="cmpE48528C4F5932A4EFD89F7331108F45D" Guid="*">
<File Id="filF1B84C2C6BCC693224B7A7959445B74F" KeyPath="yes" TrueType="yes" Source="$(var.SourceDir)\MyFont.ttf" />
</Component>
<Component Id="cmpE48528C4F5932A4EFD89F7331108F45D" Guid="*">
<File Id="filF1B84C2C6BCC693224B7A7959445B74F" KeyPath="yes" Source="$(var.SourceDir)\Newtonsoft.Json.dll" />
</Component>
</DirectoryRef>
</Fragment>
</Wix>
这是我目前使用的 XSLT,但它(还)不起作用:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
exclude-result-prefixes="msxsl"
xmlns:wix="http://schemas.microsoft.com/wix/2006/wi"
xmlns:my="my:my">
<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match='//File[ends-with(@Source , 'ttf')]'>
<xsl:attribute name="TrueType">
<xsl:value-of select="yes"/>
</xsl:attribute>
</xsl:template>
</xsl:stylesheet>
如何应用这个 ends-with() 函数?
您可以通过以下方式执行此操作:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:wi="http://schemas.microsoft.com/wix/2006/wi"
version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="wi:File">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:if test="substring(@Source,string-length(@Source)-2)='ttf'">
<xsl:attribute name="TrueType">yes</xsl:attribute>
</xsl:if>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
我有这个 wix (.wxs) 文件示例:
<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Fragment>
<DirectoryRef Id="INSTALLLOCATION">
<Component Id="cmpE48528C4F5932A4EFD89F7331108F45D" Guid="*">
<File Id="filF1B84C2C6BCC693224B7A7959445B74F" KeyPath="yes" Source="$(var.SourceDir)\MyFont.ttf" />
</Component>
<Component Id="cmpE48528C4F5932A4EFD89F7331108F45D" Guid="*">
<File Id="filF1B84C2C6BCC693224B7A7959445B74F" KeyPath="yes" Source="$(var.SourceDir)\Newtonsoft.Json.dll" />
</Component>
</DirectoryRef>
</Fragment>
</Wix>
现在我想将属性 TrueType="yes"
添加到 Source 以 'ttf' 结尾的所有文件元素。
所以它应该是这样的:
<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Fragment>
<DirectoryRef Id="INSTALLLOCATION">
<Component Id="cmpE48528C4F5932A4EFD89F7331108F45D" Guid="*">
<File Id="filF1B84C2C6BCC693224B7A7959445B74F" KeyPath="yes" TrueType="yes" Source="$(var.SourceDir)\MyFont.ttf" />
</Component>
<Component Id="cmpE48528C4F5932A4EFD89F7331108F45D" Guid="*">
<File Id="filF1B84C2C6BCC693224B7A7959445B74F" KeyPath="yes" Source="$(var.SourceDir)\Newtonsoft.Json.dll" />
</Component>
</DirectoryRef>
</Fragment>
</Wix>
这是我目前使用的 XSLT,但它(还)不起作用:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
exclude-result-prefixes="msxsl"
xmlns:wix="http://schemas.microsoft.com/wix/2006/wi"
xmlns:my="my:my">
<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match='//File[ends-with(@Source , 'ttf')]'>
<xsl:attribute name="TrueType">
<xsl:value-of select="yes"/>
</xsl:attribute>
</xsl:template>
</xsl:stylesheet>
如何应用这个 ends-with() 函数?
您可以通过以下方式执行此操作:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:wi="http://schemas.microsoft.com/wix/2006/wi"
version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="wi:File">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:if test="substring(@Source,string-length(@Source)-2)='ttf'">
<xsl:attribute name="TrueType">yes</xsl:attribute>
</xsl:if>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>