0

我有一个 azure 服务定义文件,我需要通过在末尾添加一个值来更新一些"physicalDirectory"属性 ( where @ph != 'EmptyFolder') 。'\Deploy\'

我认为查询的内容xPath's是这样的

//x:Site[@physicalDirectory != 'EmptyFolder']/@physicalDirectory
//x:VirtualApplication/@physicalDirectory

所以最终结果是这样的:

<vApp name="main" physicalDirectory="..\blahblahblah\Deploy\" />

你能帮我做吗?

这是一个示例文件

<ServiceDefinition name="Platform.Services.Azure" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition" schemaVersion="2012-05.1.7">
  <WorkerRole name="WorkflowService.Worker" vmsize="ExtraSmall">
    <Imports>
      <Import moduleName="Diagnostics" />
      <Import moduleName="RemoteAccess" />
    </Imports>
    <Certificates>
      <Certificate name="ThreeSeventyCertificate" storeLocation="LocalMachine" storeName="My" />
    </Certificates>
  </WorkerRole>
  <WebRole name="WebService.Web" vmsize="ExtraSmall" enableNativeCodeExecution="true">
     <Sites>
      <Site name="Web" physicalDirectory="EmptyFolder">
        <VirtualDirectory name="api" physicalDirectory="EmptyFolder">
          <VirtualApplication name="main" physicalDirectory="..\Platform.Services.AccountService.Web\" />
          <VirtualApplication name="v1.0" physicalDirectory="..\..\_releases\V1.0\Platform.Services.AccountService.Web\" />
        </VirtualDirectory>
        <VirtualDirectory name="docs" physicalDirectory="EmptyFolder">
          <VirtualApplication name="main" physicalDirectory="..\AccountService.Documentation\" />
          <VirtualApplication name="v1.0" physicalDirectory="..\..\_releases\V1.0\AccountService.Documentation\" />
        </VirtualDirectory>
        <VirtualApplication name="reports" physicalDirectory="..\Platform.Services.ReportService.Web\" />
        <Bindings>
          <Binding name="Endpoint1" endpointName="Endpoint1" />
        </Bindings>
      </Site>
      <Site name="internal" physicalDirectory="..\InternalService.Web\">
        <Bindings>
          <Binding name="internal" endpointName="internal" />
        </Bindings>
      </Site>
    </Sites>
    <Endpoints>
      <InputEndpoint name="Endpoint1" protocol="https" port="443" certificate="ThreeSeventy" />
      <InternalEndpoint name="internal" protocol="http">
      </InternalEndpoint>
    </Endpoints>
    <Imports>
      <Import moduleName="Diagnostics" />
      <Import moduleName="RemoteAccess" />
    </Imports>
    <Certificates>
      <Certificate name="ThreeSeventy" storeLocation="LocalMachine" storeName="My" />
    </Certificates>
    <ConfigurationSettings>
      <Setting name="TransportServiceEntities" />
      <Setting name="ReportServiceEntities" />
      <Setting name="AccountServiceEntities" />
      <Setting name="ThreeSeventyEntitiesMembership" />
    </ConfigurationSettings>
  </WebRole>
  <WorkerRole name="ChannelService.Worker" vmsize="ExtraSmall">
    <Imports>
      <Import moduleName="Diagnostics" />
      <Import moduleName="RemoteAccess" />
      <Import moduleName="RemoteForwarder" />
    </Imports>
    <ConfigurationSettings>
      <Setting name="EngineEnabled" />
      <Setting name="PlatFormAPIConnectionString" />
    </ConfigurationSettings>
    <Certificates>
      <Certificate name="ThreeSeventyCertificate" storeLocation="LocalMachine" storeName="My" />
    </Certificates>
  </WorkerRole>
</ServiceDefinition>
4

1 回答 1

1

How's this:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>

  <xsl:template match="@* | node()">
    <xsl:copy>
      <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="@physicalDirectory[. != 'EmptyFolder']">
    <xsl:attribute name="{name()}">
      <xsl:value-of select="concat(., 'Deploy\')"/>
    </xsl:attribute>
  </xsl:template>
</xsl:stylesheet>

When run on your sample input, physicalDirectory attributes with the value "EmptyFolder" are left alone:

  <Site name="Web" physicalDirectory="EmptyFolder">
    <VirtualDirectory name="api" physicalDirectory="EmptyFolder">

And all others have `Deploy\' appended to the end:

  <VirtualApplication name="main" physicalDirectory="..\Platform.Services.AccountService.Web\Deploy\" />
  <VirtualApplication name="v1.0" physicalDirectory="..\..\_releases\V1.0\Platform.Services.AccountService.Web\Deploy\" />
于 2013-02-05T11:57:39.067 回答