visual-studio - XSLT 1.0 修改配置文件替换功能

标签 visual-studio xslt xslt-1.0

我正在尝试编写 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/

相关文章:

c# - 从代码库中提取 API

java - 获取 XML 标签的 XPath

xslt - XSLT 1.0中的"Regular expression"-style替换

xml - 在 XSLT 1.0 中设置 24 小时制格式的最佳方式是什么?

xml - 在 xslt 模板中创建 key

.net - 调试VS 2005提示 "Operation not supported"

c# - 如何从默认选项创 build 置文件?

visual-studio - 如何确定哪些 Visual Studio 解决方案使用哪些项目?

xslt - xsl :sort: sorting by numeric value

xml - 如何在元素中检测文本节点