代码之家  ›  专栏  ›  技术社区  ›  Princess

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

  •  2
  • Princess  · 技术社区  · 7 年前

    我正在尝试编写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>
    
    1 回复  |  直到 7 年前
        1
  •  2
  •   michael.hor257k    7 年前

    这对你有用吗?

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