Topic
  • 2 replies
  • Latest Post - ‏2013-08-02T13:18:07Z by swlinn
samuels
samuels
64 Posts

Pinned topic Routing xslt by using client uri

‏2013-08-02T03:43:14Z |

Hello , I am new to Data Power. I am very poor in writing xslt's. I am trying to transform by using the incoming uri from client(soapUI). i need to route when i get request with the uri  /MPGW1 . I need to route that request to the service. i.e. MPGW1 . like that if i get the request with the uri /MPGW2 is should be routed to the service MPGW2. like these i have following xml. please help me in writing the xslt.

Here is my XML

 

<?xml version="1.0" encoding="UTF-8"?>
<route>
<service name=" MPGW1" endpoint="https://x.x.x.x:xx86/MPGW1" sslprofile="SSL Proxy Profile: 1SSL_Proxy_profile"/>
<service name=" MPGW2" endpoint="http://x.x.x.x:xx78/MPGW2" sslprofile=""/>
<service name=" MPGW3" endpoint="http://x.x.x.x:9xx9/MPGW3" sslproxy=""/>
<service name=" MPGW4" endpoint="https://x.x.x.x:xx8/MPGW4" sslproxy="SSL Proxy Profile: 4SSL_Proxy_profile"/>
</route>

 

I would like to write xslt by using these information. any help would be appreciated to write the xslt.

 

Thank you

 
Updated on 2013-08-02T03:51:01Z at 2013-08-02T03:51:01Z by samuels
  • David07
    David07
    73 Posts

    Re: Routing xslt by using client uri

    ‏2013-08-02T04:37:28Z  

    Hi,

    Try with the below stylesheet code,

     

    <?xml version="1.0" encoding="UTF-8"?>

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:dp="http://www.datapower.com/extensions"

    extension-element-prefixes="dp"

    exclude-result-prefixes="dp">

    <xsl:output method="xml"/>

     

    <xsl:variable name="URI" select="document('property.xml')/route"/>

    <xsl:template match="/">

    <xsl:variable name="IncomingURI">

    <xsl:value-of select="dp:variable('var://service/URI')"/>

    <xsl:choose>

    <xsl:when test="$URI/service/@name[1] = $IncomingURI">

    <xsl:variable name="backEndUrl" select="$URI/service/@endpoint[1]" />

    <dp:set-variable name="'var://service/routing-url'" value="$backEndUrl" />

    </xsl:when>

    <xsl:when test="$URI/service/@name[2] = $IncomingURI">

    <xsl:variable name="backEndUrl" select="$URI/service/@endpoint[2]" />

    <dp:set-variable name="'var://service/routing-url'" value="$backEndUrl" />

    </xsl:when>

    <xsl:when test="$URI/service/@name[3] = $IncomingURI">

    <xsl:variable name="backEndUrl" select="$URI/service/@endpoint[3]" />

    <dp:set-variable name="'var://service/routing-url'" value="$backEndUrl" />

    </xsl:when>

    <xsl:when test="$URI/service/@name[4] = $IncomingURI">

    <xsl:variable name="backEndUrl" select="$URI/service/@endpoint[4]" />

    <dp:set-variable name="'var://service/routing-url'" value="$backEndUrl" />

    </xsl:when>

    </xsl:choose>

    </xsl:variable>

    </xsl:template>

    </xsl:stylesheet>

     

     

    Regards,

    David.

    Updated on 2013-08-02T04:38:36Z at 2013-08-02T04:38:36Z by David07
  • swlinn
    swlinn
    1348 Posts

    Re: Routing xslt by using client uri

    ‏2013-08-02T13:18:07Z  
    • David07
    • ‏2013-08-02T04:37:28Z

    Hi,

    Try with the below stylesheet code,

     

    <?xml version="1.0" encoding="UTF-8"?>

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:dp="http://www.datapower.com/extensions"

    extension-element-prefixes="dp"

    exclude-result-prefixes="dp">

    <xsl:output method="xml"/>

     

    <xsl:variable name="URI" select="document('property.xml')/route"/>

    <xsl:template match="/">

    <xsl:variable name="IncomingURI">

    <xsl:value-of select="dp:variable('var://service/URI')"/>

    <xsl:choose>

    <xsl:when test="$URI/service/@name[1] = $IncomingURI">

    <xsl:variable name="backEndUrl" select="$URI/service/@endpoint[1]" />

    <dp:set-variable name="'var://service/routing-url'" value="$backEndUrl" />

    </xsl:when>

    <xsl:when test="$URI/service/@name[2] = $IncomingURI">

    <xsl:variable name="backEndUrl" select="$URI/service/@endpoint[2]" />

    <dp:set-variable name="'var://service/routing-url'" value="$backEndUrl" />

    </xsl:when>

    <xsl:when test="$URI/service/@name[3] = $IncomingURI">

    <xsl:variable name="backEndUrl" select="$URI/service/@endpoint[3]" />

    <dp:set-variable name="'var://service/routing-url'" value="$backEndUrl" />

    </xsl:when>

    <xsl:when test="$URI/service/@name[4] = $IncomingURI">

    <xsl:variable name="backEndUrl" select="$URI/service/@endpoint[4]" />

    <dp:set-variable name="'var://service/routing-url'" value="$backEndUrl" />

    </xsl:when>

    </xsl:choose>

    </xsl:variable>

    </xsl:template>

    </xsl:stylesheet>

     

     

    Regards,

    David.

    You can also generalize the above by something like the following (coded on the fly and not tested, but hopefully in the ballpark)

    <xsl:variable name="route" select="$URI/service[@name=$IncomingURI"]/endpoint/text()" />

    <xsl:if test="$route">

        <xsl:variable name="sslprofile" select="$URI/service[@name=$IncomingURI]/sslprofile" />

        <xsl:if test="starts-with($route, 'https') and $sslprofile">

            <dp:set-variable name="'var://service/routing-url-sslprofile'" value="$sslprofile" />

        </xsl:if>

        <dp:set-variable name="'var://service/routing-url'" value="$route" />

    </xsl:if>

    Regards,

    Steve