Visual studio XSLT 1.0修改配置文件替换函数

Visual studio XSLT 1.0修改配置文件替换函数,visual-studio,xslt,xslt-1.0,Visual Studio,Xslt,Xslt 1.0,我正在尝试编写XSLT来修改配置文件。我尝试过使用replace函数,但这仅在2.0中受支持,我也尝试过使用translate,但与“false”相关的“true”trn被截断为“fals”。我不能仅仅更换整个模块部分,因为我们的客户处于分布式环境中,我不知道他们是否在该部分添加了其他内容。 我从以下几点开始: <modules runAllManagedModulesForAllRequests="true"> <remove name="FormsAuthentic

我正在尝试编写XSLT来修改配置文件。我尝试过使用replace函数,但这仅在2.0中受支持,我也尝试过使用translate,但与“false”相关的“true”trn被截断为“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>

这对你有用吗

XSLT1.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>

假的

FYI-之所以
translate()
没有达到预期效果,是因为它没有对单词或整个字符串值执行查找/替换,而是基于字符的。指定要转换的字符,并用第二个参数中该位置的字符替换。如果没有对应的字符,则将其删除。i、 e.
translate(,'false','true')
表示将“f”替换为“t”,将“a”替换为“r”,将“l”替换为“u”,将“e”替换为“u”。