我正在尝试编写 XSLT 来修改配置文件。我尝试使用替换功能,但仅在 2.0 中受支持,并且我尝试使用翻译,但“true”翻译为“false”会被截断为“fals”。我不能只替换整个模块部分,因为我们的客户处于分布式环境中,我不知道他们是否在该部分中添加了任何其他内容。 我从什么开始:
<modules runAllManagedModulesForAllRequests="true">
<remove name="FormsAuthentication" />
</modules>
期望的输出:
<modules runAllManagedModulesForAllRequests="false">
<remove name="FormsAuthentication" />
</modules>
这就是我认为可以解决问题的方法。
<xsl:template match="/configuration/system.webServer/modules">
<xsl:choose>
<xsl:when test="@name=runAllManagedModulesForAllRequests">
<xsl:copy>
<xsl:copy-of select="<modules runAllManagedModulesForAllRequests="false">"/>
</xsl:copy>
</xsl:when>
<xsl:otherwise>
<xsl:copy>
<xsl:copy-of select="@*"/>
</xsl:copy>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
最佳答案
这对你有用吗?
XSLT 1.0
<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:strip-space elements="*"/>
<!-- identity transform -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="@runAllManagedModulesForAllRequests[.='true']">
<xsl:attribute name="runAllManagedModulesForAllRequests">false</xsl:attribute>
</xsl:template>
</xsl:stylesheet>
关于visual-studio - XSLT 1.0 修改配置文件替换功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54408790/