Monday, 28 July 2014

Replace parts of string on line using XSLT 2



I have a WSDL, in which I would like to override the soap address location using XSLT 2.0.


For example: <soap:address location="http://ift.tt/1lLWWjm"/>


For the location attribute, I would like 1) xyz.company.com to become abc.company.com 2) myapp to become xyzapp.


I have written the following xslt:



<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://ift.tt/tCZ8VR" version="2.0" xmlns:soap="http://ift.tt/KIQHA2" xmlns:soapenc="http://ift.tt/wEYywg" xmlns:wsdl="http://ift.tt/LcBaVt">

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


This works for replacing point 1 -> xyz.company.com to become abc.company.com.


But how can I also replace point 2. -> myapp to become xyzapp


Please advise.


Thanks,


No comments:

Post a Comment