我有一个 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/