Topic
  • 11 replies
  • Latest Post - ‏2012-12-03T19:16:09Z by Nivast
Nivast
Nivast
25 Posts

Pinned topic How to store and retrive multiple values into varaible in XSLT?Datapower

‏2012-12-02T21:59:55Z |
Hi,

Can anyone help xslt in datapower?How to retrieve multiple values into variable in XSLT?i want to store "applroles" values into variable.
<result>
<attribute-value name="applroles">ABCD</attribute-value>
<attribute-value name="applroles">XYZ</attribute-value>
<attribute-value name="applroles">EFGH</attribute-value>
</result>
I tried to use below query but it is storing only one value into variable.
<xsl:variable name="appRole1">
<xsl:copy-of select="string($appRoles/*/*[local-name()='attribute-value' and @*)"/>
</xsl:variable>

appRole1 always displaying ABCD but i need remaining values also in appRole1.(applroles values are dynamic not always the same).
Updated on 2012-12-03T19:16:09Z at 2012-12-03T19:16:09Z by Nivast
  • kenhygh
    kenhygh
    1522 Posts

    Re: How to store and retrive multiple values into varaible in XSLT?Datapower

    ‏2012-12-02T23:34:13Z  
    <xsl:variable name="appRole1">
    <xsl:copy-of select="$appRoles/result"/>
    </xsl:variable>

    Ken
  • Nivast
    Nivast
    25 Posts

    Re: How to store and retrive multiple values into varaible in XSLT?Datapower

    ‏2012-12-03T00:43:18Z  
    • kenhygh
    • ‏2012-12-02T23:34:13Z
    <xsl:variable name="appRole1">
    <xsl:copy-of select="$appRoles/result"/>
    </xsl:variable>

    Ken
    HI Ken,

    Thank you very much for the response.But i need "applroles" values into one variable.

    example: variable app="ABCD,XYZ,EFG"

    I used this code but it is stroring only first "applroles" value but i need all values into one variable.

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:dp="http://www.datapower.com/extensions" extension-element-prefixes="dp" exclude-result-prefixes="dp" version="1.0">
    <xsl:output method="xml"/>
    <xsl:template match="/">
    <xsl:variable name="appRoles">
    <xsl:copy-of select="dp:variable('var://context/ldap/auxiliary-attributes')"/>
    </xsl:variable>
    <xsl:copy>
    <xsl:variable name="appRole">
    <xsl:copy-of select="."/>
    <xsl:copy-of select="string($appRoles/*/*[local-name()='attribute-value' and @*)"/>

    </xsl:variable>
    <xsl:for-each select="$appRole">
    <xsl:message dp:priority="debug">
    DEBUG ** Value of appRole is <xsl:copy-of select="$appRole"/>
    </xsl:message>
    </xsl:for-each>
    </xsl:copy>
    </xsl:template>
    </xsl:stylesheet>

    Please help me.
  • SystemAdmin
    SystemAdmin
    6772 Posts

    Re: How to store and retrive multiple values into varaible in XSLT?Datapower

    ‏2012-12-03T01:17:36Z  
    • Nivast
    • ‏2012-12-03T00:43:18Z
    HI Ken,

    Thank you very much for the response.But i need "applroles" values into one variable.

    example: variable app="ABCD,XYZ,EFG"

    I used this code but it is stroring only first "applroles" value but i need all values into one variable.

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:dp="http://www.datapower.com/extensions" extension-element-prefixes="dp" exclude-result-prefixes="dp" version="1.0">
    <xsl:output method="xml"/>
    <xsl:template match="/">
    <xsl:variable name="appRoles">
    <xsl:copy-of select="dp:variable('var://context/ldap/auxiliary-attributes')"/>
    </xsl:variable>
    <xsl:copy>
    <xsl:variable name="appRole">
    <xsl:copy-of select="."/>
    <xsl:copy-of select="string($appRoles/*/*[local-name()='attribute-value' and @*)"/>

    </xsl:variable>
    <xsl:for-each select="$appRole">
    <xsl:message dp:priority="debug">
    DEBUG ** Value of appRole is <xsl:copy-of select="$appRole"/>
    </xsl:message>
    </xsl:for-each>
    </xsl:copy>
    </xsl:template>
    </xsl:stylesheet>

    Please help me.
    Much easier in XSLT 2.0 but you don't have that option in DataPower yet.

    Try something like this:
    
    <xsl:stylesheet xmlns:xsl=
    "http://www.w3.org/1999/XSL/Transform" xmlns:dp=
    "http://www.datapower.com/extensions" extension-element-prefixes=
    "dp" exclude-result-prefixes=
    "dp" version=
    "1.0"> <xsl:output method=
    "xml"/> <xsl:template match=
    "/"> <xsl:variable name=
    "appRoles"> <xsl:copy-of select=
    "dp:variable('var://context/ldap/auxiliary-attributes')"/> </xsl:variable> <xsl:variable name=
    "appRolesCommaSep"> <xsl:apply-templates select=
    "$appRoles/result/attribute-value[@name='applroles']" mode=
    "concatRoles"/> </xsl:variable> <xsl:message dp:priority=
    "debug"> <xsl:text>DEBUG ** Value of appRolesCommaSep is </xsl:text> <xsl:value-of select=
    "$appRolesCommaSep"/> </xsl:message> </xsl:template> <xsl:template match=
    "attribute-value" mode=
    "concatRoles"> <xsl:value-of select=
    "text()"/> <xsl:
    
    if test=
    "position() != last()"> <xsl:text>,</xsl:text> </xsl:if> </xsl:template> </xsl:stylesheet>
    
  • Nivast
    Nivast
    25 Posts

    Re: How to store and retrive multiple values into varaible in XSLT?Datapower

    ‏2012-12-03T03:50:11Z  
    Much easier in XSLT 2.0 but you don't have that option in DataPower yet.

    Try something like this:
    <pre class="jive-pre"> <xsl:stylesheet xmlns:xsl= "http://www.w3.org/1999/XSL/Transform" xmlns:dp= "http://www.datapower.com/extensions" extension-element-prefixes= "dp" exclude-result-prefixes= "dp" version= "1.0"> <xsl:output method= "xml"/> <xsl:template match= "/"> <xsl:variable name= "appRoles"> <xsl:copy-of select= "dp:variable('var://context/ldap/auxiliary-attributes')"/> </xsl:variable> <xsl:variable name= "appRolesCommaSep"> <xsl:apply-templates select= "$appRoles/result/attribute-value[@name='applroles']" mode= "concatRoles"/> </xsl:variable> <xsl:message dp:priority= "debug"> <xsl:text>DEBUG ** Value of appRolesCommaSep is </xsl:text> <xsl:value-of select= "$appRolesCommaSep"/> </xsl:message> </xsl:template> <xsl:template match= "attribute-value" mode= "concatRoles"> <xsl:value-of select= "text()"/> <xsl: if test= "position() != last()"> <xsl:text>,</xsl:text> </xsl:if> </xsl:template> </xsl:stylesheet> </pre>
    Thank you very much Nick,its worked but one more help.
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:dp="http://www.datapower.com/extensions" extension-element-prefixes="dp" exclude-result-prefixes="dp" version="1.0">
    <xsl:output method="xml"/>
    <xsl:template match="/">
    <xsl:variable name="appRoles">
    <xsl:copy-of select="dp:variable('var://context/ldap/auxiliary-attributes')"/>
    </xsl:variable>
    <xsl:variable name="appRolesCommaSep">
    <xsl:apply-templates select="$appRoles/result/attribute-value" mode="concatRoles"/>
    </xsl:variable>
    <xsl:variable name="request-opname" select="dp:http-request-header('SOAPAction')"/>
    <xsl:choose>
    <xsl:when test="contains($appRolesCommaSep,'op')">
    <xsl:variable name="request-opname-laststring">
    <xsl:value-of select="substring-after('op_,'_')"/>
    </xsl:variable>
    <xsl:message dp:priority="debug">
    <xsl:text>DEBUG ** Value of operation is </xsl:text>
    <xsl:value-of select="$request-opname-laststring"/>
    </xsl:message>
    </xsl:when>

    <xsl:when test="contains($request-opname,'$request-opname-laststring')">
    <xsl:text>DEBUG ** Value of operation is true</xsl:text>
    <dp:accept/>
    </xsl:when>

    <xsl:otherwise>
    <dp:reject/>
    </xsl:otherwise>

    </xsl:choose>
    </xsl:template>
    <xsl:template match="attribute-value" mode="concatRoles">
    <xsl:value-of select="text()"/>
    <xsl:if test="position() != last()">
    <xsl:text>,</xsl:text>
    </xsl:if>
    </xsl:template>
    </xsl:stylesheet>
    here appRolesCommaSep is giving correct value(v1_op_GetEntry) but i want to get last "Getentry" into other variable so that i can compare.
    Please advice me.
  • SystemAdmin
    SystemAdmin
    6772 Posts

    Re: How to store and retrive multiple values into varaible in XSLT?Datapower

    ‏2012-12-03T04:51:41Z  
    • Nivast
    • ‏2012-12-03T03:50:11Z
    Thank you very much Nick,its worked but one more help.
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:dp="http://www.datapower.com/extensions" extension-element-prefixes="dp" exclude-result-prefixes="dp" version="1.0">
    <xsl:output method="xml"/>
    <xsl:template match="/">
    <xsl:variable name="appRoles">
    <xsl:copy-of select="dp:variable('var://context/ldap/auxiliary-attributes')"/>
    </xsl:variable>
    <xsl:variable name="appRolesCommaSep">
    <xsl:apply-templates select="$appRoles/result/attribute-value" mode="concatRoles"/>
    </xsl:variable>
    <xsl:variable name="request-opname" select="dp:http-request-header('SOAPAction')"/>
    <xsl:choose>
    <xsl:when test="contains($appRolesCommaSep,'op')">
    <xsl:variable name="request-opname-laststring">
    <xsl:value-of select="substring-after('op_,'_')"/>
    </xsl:variable>
    <xsl:message dp:priority="debug">
    <xsl:text>DEBUG ** Value of operation is </xsl:text>
    <xsl:value-of select="$request-opname-laststring"/>
    </xsl:message>
    </xsl:when>

    <xsl:when test="contains($request-opname,'$request-opname-laststring')">
    <xsl:text>DEBUG ** Value of operation is true</xsl:text>
    <dp:accept/>
    </xsl:when>

    <xsl:otherwise>
    <dp:reject/>
    </xsl:otherwise>

    </xsl:choose>
    </xsl:template>
    <xsl:template match="attribute-value" mode="concatRoles">
    <xsl:value-of select="text()"/>
    <xsl:if test="position() != last()">
    <xsl:text>,</xsl:text>
    </xsl:if>
    </xsl:template>
    </xsl:stylesheet>
    here appRolesCommaSep is giving correct value(v1_op_GetEntry) but i want to get last "Getentry" into other variable so that i can compare.
    Please advice me.
    So what exactly are you trying to achieve?
    It looks like you're trying to test if part of the request SOAPAction is contained in a list of auth roles that you have retrieved from an LDAP repository.
    If you re-phrase your requirement in those terms you'll get a much nicer solution.
    (It's unlikely that you require a comma seperated temporary variable for instance).

    So I suggest you post back with something like:

    *************************************
    I've got a request SOAP action like this:
    http://www.foo.com/services/GetEntry

    And a list of roles like this:
    <result>
    <attribute-value name="applroles">ABCD</attribute-value>
    <attribute-value name="applroles">XYZ</attribute-value>
    <attribute-value name="applroles">EFGH</attribute-value>
    </result>

    What is the best way for me to test if (and so on.......)
    *************************************

    Cheers.
  • Nivast
    Nivast
    25 Posts

    Re: How to store and retrive multiple values into varaible in XSLT?Datapower

    ‏2012-12-03T05:14:04Z  
    So what exactly are you trying to achieve?
    It looks like you're trying to test if part of the request SOAPAction is contained in a list of auth roles that you have retrieved from an LDAP repository.
    If you re-phrase your requirement in those terms you'll get a much nicer solution.
    (It's unlikely that you require a comma seperated temporary variable for instance).

    So I suggest you post back with something like:

    *************************************
    I've got a request SOAP action like this:
    http://www.foo.com/services/GetEntry

    And a list of roles like this:
    <result>
    <attribute-value name="applroles">ABCD</attribute-value>
    <attribute-value name="applroles">XYZ</attribute-value>
    <attribute-value name="applroles">EFGH</attribute-value>
    </result>

    What is the best way for me to test if (and so on.......)
    *************************************

    Cheers.
    Hi Nick,

    Thank you very much for the quick response.That is what exactly i am trying.
    Here is the task i am trying to restrict webservice in service level and operation level based on ldap roles(Authorization level).For example one service has 3 operations
    I have SOAPAction values like this
    http://test/V1/VehicleLifecycleServicePortType/GetEntry
    http://test/V1/VehicleLifecycleServicePortType/GetEQuipement

    userA:ldap roles like this(This is service level restriction)
    ws_edm_ TestService_v1_svc
    ATT_TEST

    UserB:ldap roles(This is operation level restriction)
    ws_edm_TestService_v1_op_GetEntry
    TEST_ARole
    Test_ROle

    userA don't have (op) in LDAP roles so that userA can able to access all operations.
    userB having (op) in LDAP role so that i have to restrict userB to allow only (http://test/V1/VehicleLifecycleServicePortType/GetEntry) this operation but not all operations.(all are dynamic and iam trying to use this for all webservices).
    Webservice access user should be having role start with(ws_edm_***) using ws_edm only i tried to accomplish this.

    How to get the last word from SOAPAction value(GetEntry).
    Please help me on this.Thanks in Advance.
  • Nivast
    Nivast
    25 Posts

    Re: How to store and retrive multiple values into varaible in XSLT?Datapower

    ‏2012-12-03T05:15:30Z  
    • Nivast
    • ‏2012-12-03T05:14:04Z
    Hi Nick,

    Thank you very much for the quick response.That is what exactly i am trying.
    Here is the task i am trying to restrict webservice in service level and operation level based on ldap roles(Authorization level).For example one service has 3 operations
    I have SOAPAction values like this
    http://test/V1/VehicleLifecycleServicePortType/GetEntry
    http://test/V1/VehicleLifecycleServicePortType/GetEQuipement

    userA:ldap roles like this(This is service level restriction)
    ws_edm_ TestService_v1_svc
    ATT_TEST

    UserB:ldap roles(This is operation level restriction)
    ws_edm_TestService_v1_op_GetEntry
    TEST_ARole
    Test_ROle

    userA don't have (op) in LDAP roles so that userA can able to access all operations.
    userB having (op) in LDAP role so that i have to restrict userB to allow only (http://test/V1/VehicleLifecycleServicePortType/GetEntry) this operation but not all operations.(all are dynamic and iam trying to use this for all webservices).
    Webservice access user should be having role start with(ws_edm_***) using ws_edm only i tried to accomplish this.

    How to get the last word from SOAPAction value(GetEntry).
    Please help me on this.Thanks in Advance.
    If the user don't have "op" in the ldap role no need to verify in operation level.
  • SystemAdmin
    SystemAdmin
    6772 Posts

    Re: How to store and retrive multiple values into varaible in XSLT?Datapower

    ‏2012-12-03T06:10:53Z  
    • Nivast
    • ‏2012-12-03T05:15:30Z
    If the user don't have "op" in the ldap role no need to verify in operation level.
    Here's one approach based on what you started with.
    There are many alternative ways to do the same thing.

    
    <xsl:stylesheet xmlns:xsl=
    "http://www.w3.org/1999/XSL/Transform" xmlns:dp=
    "http://www.datapower.com/extensions" extension-element-prefixes=
    "dp" exclude-result-prefixes=
    "dp" version=
    "1.0"> <xsl:output method=
    "xml" encoding=
    "UTF-8" version=
    "1.0"/> <xsl:template match=
    "/"> <xsl:variable name=
    "appRoles"> <xsl:copy-of select=
    "dp:variable('var://context/ldap/auxiliary-attributes')"/> </xsl:variable> <xsl:variable name=
    "requestSoapAction" select=
    "dp:http-request-header('SOAPAction')"/> <xsl:choose> <xsl:when test=
    "not($appRoles/result/attribute-value[@name='applroles'][starts-with(normalize-space(.),'ws_edm_')])"> <!-- Reject as unauthorised. No roles that start with 
    'ws_edm_' --> <!-- TODO - log and reject --> </xsl:when> <xsl:when test=
    "$appRoles/result/attribute-value[@name='applroles'][contains(text(),'_op_')]"> <!-- Test authorisation 
    
    for the requested operation --> <xsl:variable name=
    "requestOpname"> <xsl:call-template name=
    "GetOpFromSoapAction"> <xsl:with-param name=
    "action" select=
    "$requestSoapAction"/> </xsl:call-template> </xsl:variable> <xsl:variable name=
    "requiredAuthRole" select=
    "concat('ws_edm_TestService_v1_op_',$requestOpname)"/> <xsl:choose> <xsl:when test=
    "$appRoles/result/attribute-value[@name='applroles'][normalize-space(.) = $requiredAuthRole]
    "> <!-- User is authorised 
    
    for the requested operation --> <!-- TODO - log and accept --> </xsl:when> <xsl:otherwise> <!-- User is not authorised 
    
    for the requested operation --> <!-- TODO - log and reject --> </xsl:otherwise> </xsl:choose> </xsl:when> <xsl:otherwise> <!-- Authorised 
    
    for all operations --> <!-- TODO - log and accept --> </xsl:otherwise> </xsl:choose> </xsl:template> <!-- Recursive template to get operation from soap action --> <xsl:template name=
    "GetOpFromSoapAction"> <xsl:param name=
    "action"/> <xsl:choose> <xsl:when test=
    "contains($action,'/')"> <xsl:call-template name=
    "GetOpFromSoapAction"> <xsl:with-param name=
    "action" select=
    "substring-after($action,'/')"/> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select=
    "$action"/> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet>
    
  • Nivast
    Nivast
    25 Posts

    Re: How to store and retrive multiple values into varaible in XSLT?Datapower

    ‏2012-12-03T07:10:17Z  
    Here's one approach based on what you started with.
    There are many alternative ways to do the same thing.

    <pre class="jive-pre"> <xsl:stylesheet xmlns:xsl= "http://www.w3.org/1999/XSL/Transform" xmlns:dp= "http://www.datapower.com/extensions" extension-element-prefixes= "dp" exclude-result-prefixes= "dp" version= "1.0"> <xsl:output method= "xml" encoding= "UTF-8" version= "1.0"/> <xsl:template match= "/"> <xsl:variable name= "appRoles"> <xsl:copy-of select= "dp:variable('var://context/ldap/auxiliary-attributes')"/> </xsl:variable> <xsl:variable name= "requestSoapAction" select= "dp:http-request-header('SOAPAction')"/> <xsl:choose> <xsl:when test= "not($appRoles/result/attribute-value[@name='applroles'][starts-with(normalize-space(.),'ws_edm_')])"> <!-- Reject as unauthorised. No roles that start with 'ws_edm_' --> <!-- TODO - log and reject --> </xsl:when> <xsl:when test= "$appRoles/result/attribute-value[@name='applroles'][contains(text(),'_op_')]"> <!-- Test authorisation for the requested operation --> <xsl:variable name= "requestOpname"> <xsl:call-template name= "GetOpFromSoapAction"> <xsl:with-param name= "action" select= "$requestSoapAction"/> </xsl:call-template> </xsl:variable> <xsl:variable name= "requiredAuthRole" select= "concat('ws_edm_TestService_v1_op_',$requestOpname)"/> <xsl:choose> <xsl:when test= "$appRoles/result/attribute-value[@name='applroles'][normalize-space(.) = $requiredAuthRole] "> <!-- User is authorised for the requested operation --> <!-- TODO - log and accept --> </xsl:when> <xsl:otherwise> <!-- User is not authorised for the requested operation --> <!-- TODO - log and reject --> </xsl:otherwise> </xsl:choose> </xsl:when> <xsl:otherwise> <!-- Authorised for all operations --> <!-- TODO - log and accept --> </xsl:otherwise> </xsl:choose> </xsl:template> <!-- Recursive template to get operation from soap action --> <xsl:template name= "GetOpFromSoapAction"> <xsl:param name= "action"/> <xsl:choose> <xsl:when test= "contains($action,'/')"> <xsl:call-template name= "GetOpFromSoapAction"> <xsl:with-param name= "action" select= "substring-after($action,'/')"/> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select= "$action"/> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet> </pre>
    Thanks a lot Nick,its worked perfectly except this change.

    <xsl:variable name="requiredAuthRole" select="concat('ws_edm_TestService_v1_op_',$requestOpname)"/>
    <xsl:choose>
    <xsl:when test="$appRoles/result/attribute-value[normalize-space(.) =
    $requiredAuthRole]">
    <!-- User is authorised for the requested operation -->
    <!-- TODO - log and accept -->
    </xsl:when>

    to
    <xsl:variable name="appRolesCommaSep">
    <xsl:apply-templates select="$appRoles/result/attribute-value" mode="concatRoles"/>
    </xsl:variable>

    <xsl:choose>

    <xsl:when test="contains($appRolesCommaSep,'op')">
    <dp:accept/>

    here also we know only "op" not this ws_edm_TestService_v1_op_.

    thats why i can't able to display the full ldap role(i used contains).
  • Nivast
    Nivast
    25 Posts

    Re: How to store and retrive multiple values into varaible in XSLT?Datapower

    ‏2012-12-03T07:39:09Z  
    • Nivast
    • ‏2012-12-03T07:10:17Z
    Thanks a lot Nick,its worked perfectly except this change.

    <xsl:variable name="requiredAuthRole" select="concat('ws_edm_TestService_v1_op_',$requestOpname)"/>
    <xsl:choose>
    <xsl:when test="$appRoles/result/attribute-value[normalize-space(.) =
    $requiredAuthRole]">
    <!-- User is authorised for the requested operation -->
    <!-- TODO - log and accept -->
    </xsl:when>

    to
    <xsl:variable name="appRolesCommaSep">
    <xsl:apply-templates select="$appRoles/result/attribute-value" mode="concatRoles"/>
    </xsl:variable>

    <xsl:choose>

    <xsl:when test="contains($appRolesCommaSep,'op')">
    <dp:accept/>

    here also we know only "op" not this ws_edm_TestService_v1_op_.

    thats why i can't able to display the full ldap role(i used contains).
    <xsl:when test="contains($appRolesCommaSep,'op')">

    If appRolesCommaSep contains "op" how to store only that approle into variable?

    Thank you Nick.
  • Nivast
    Nivast
    25 Posts

    Re: How to store and retrive multiple values into varaible in XSLT?Datapower

    ‏2012-12-03T19:16:09Z  
    • Nivast
    • ‏2012-12-03T07:39:09Z
    <xsl:when test="contains($appRolesCommaSep,'op')">

    If appRolesCommaSep contains "op" how to store only that approle into variable?

    Thank you Nick.
    HI Nick,

    It is working for only one operation and one service .

    example:
    1.ServiceA
    a.OperationA
    b.OperationB
    so on..
    2.ServiceB
    c.OperationC
    d.OperationD
    so on..
    3.ServiceC
    E.operationE

    userA:able to access
    ServiceA(all operations) and OperationC,OperationD

    userB:able to access
    ServiceB(all operations) and OperationA only

    like that.I tried to use for each to repeat the loop but didn't worked.
    Please help me.