XSLT转换无法模板匹配

问题描述 投票:2回答:1

我正在尝试使用XSLT转换在XML上执行查找和替换。我以为我可以使用XPath模板匹配元素,选择我想要转换的属性(Value)然后使用xsl:value-of select =“”更改它。我有一个类似的工作示例,这是我用来构建这个尝试。查找和替换来自此示例,我确信它不会导致转换失败。

XML:

    <?xml version="1.0" encoding="utf-8"?>
    <Site xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Description="Basic Cadastre layers with Imagery layers " DisplayName="bwi" DisplayTimeZoneID="Australia/Canberra" ID="bwi" SignInEnabled="false" SignOutEnabled="false" SplashScreenUrl="{RestVirtualDirectoryUrl}/Images/Icons/SplashScreen_bwi.png" TimeZoneID="Australia/Canberra" Version="4.6.2">
      <Workflows>
        <Workflow DisplayName="AddPointXY" ID="AddPointXY" RunOnStartup="false" Uri="{RootUri}/Resources/Workflows/AddPointXY.xaml">
          <Properties>
            <Property Name="GeometryServer" Value="http://dev-data.actmapi.act.gov.au/arcgis/rest/services/Utilities/Geometry/GeometryServer" />
          </Properties>
        </Workflow>
      </Workflows>
    </Site>

XSLT:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:regexp="http://exslt.org/regular-expressions"
  extension-element-prefixes="regexp">

  <!-- Copy the document to work with -->
  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match='//Workflows/Workflow/Properties/Property'>
            <xsl:attribute name="Value">
                <xsl:value-of select="regexp:replace(string(.),'(dev-data.actmapi.act.gov.au)','gi','test-data.actmapi.act.gov.au')" />
            </xsl:attribute>    
  </xsl:template>

</xsl:stylesheet>
xml xslt
1个回答
0
投票

XSLT 2.0:

**

<?xml version="1.0"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <!-- Copy the document to work with -->
    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="//Workflows/Workflow/Properties/Property/@Value">
        <xsl:attribute name="Value">
            <xsl:value-of select="replace(.,'dev-data.actmapi.act.gov.au','test-data.actmapi.act.gov.au')" />
        </xsl:attribute>
    </xsl:template>

</xsl:stylesheet>

**

© www.soinside.com 2019 - 2024. All rights reserved.