java - 使用 XSLT 2 在线替换部分字符串

标签 java xml xslt soap

我有一个 WSDL,我想在其中使用 XSLT 2.0 覆盖 SOAP 地址位置。

例如:

对于位置属性,我想要

  • xyz.company.com 变为 abc.company.com
  • myapp 变为 xyzapp

    我编写了以下 xslt:

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
    
        <xsl:output method="xml"/>
    
    
        <xsl:template match="node()|@*">
            <xsl:copy>
            <xsl:apply-templates select="node()|@*"/>
        </xsl:copy>
        </xsl:template>
    
        <xsl:variable name="vLocation" select="wsdl:definitions/wsdl:service/wsdl:port/soap:address/@location"/>
        <xsl:template match="@location">
    
          <xsl:attribute name="location">
              <xsl:value-of select="replace($vLocation, xyz.company.com', 'abc.company.com')"/> 
          </xsl:attribute>
        </xsl:template>
    
    </xsl:stylesheet>
    

    这适用于将点 1 -> xyz.company.com 替换为 abc.company.com

    但是我怎样才能将第2点替换为myapp成为xyzapp

    请指教。

    谢谢

  • 最佳答案

    您只需再次调用replace即可,如下所示

    <xsl:template match="soap:address/@location">
      <xsl:attribute name="location" select="replace(replace(., 'xyz\.company\.com', 'abc.company.com'), 'myapp', 'xyzapp')"/>
    </xsl:template>
    

    关于java - 使用 XSLT 2 在线替换部分字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24991871/

    相关文章:

    java - 由于神秘原因,具有 POST 文件上传功能的 Apache HttpClient 无法进行基本身份验证

    java - 当 V 是 T 中的属性对象时,如何将数组 T[] 转换为 V[]

    xml - 使用 xsl 删除字符

    xml - XSLT 删除标签但保留内容

    java - 在 AsyncTask 中安全地调用 getActivity()

    java - 我需要什么 Maven 依赖项才能获取 FileCredentialStore?

    c# - 使用linq写入xml文件

    c# - 如何使用 C# .NET 从 XML 字符串中读取处理指令?

    xml - curl 剥离 xml 文件中的 CRLF

    css - 使用外部 XSL 样式表呈现本地下载的 XML 文件的回退策略