Topic
5 replies Latest Post - ‏2013-01-02T22:41:11Z by swlinn
Nivast
Nivast
25 Posts
ACCEPTED ANSWER

Pinned topic XSLT help

‏2012-12-14T19:28:52Z |
I have values in a variable

approles=(test1,test2,test3,test4)

how to print these values one by one in new line in forloop xslt?
Updated on 2013-01-02T22:41:11Z at 2013-01-02T22:41:11Z by swlinn
  • kenhygh
    kenhygh
    792 Posts
    ACCEPTED ANSWER

    Re: XSLT help

    ‏2012-12-14T20:40:06Z  in response to Nivast
    Try this:
    http://stackoverflow.com/questions/536968/xslt-recursively-working-outwards

    Ken
    • swlinn
      swlinn
      1327 Posts
      ACCEPTED ANSWER

      Re: XSLT help

      ‏2012-12-14T22:18:17Z  in response to kenhygh
      I assume you're dealing with a string, so you could strip the parens (substring-after(substring-before, and then str:tokenize with a comma delimiter. A for each over that result will let you see each item individually, so you could output each with a newline ( ).

      Regards,
      Steve
      • HermannSW
        HermannSW
        2817 Posts
        ACCEPTED ANSWER

        Re: XSLT help

        ‏2012-12-15T12:16:09Z  in response to swlinn
        Hi Nivas,

        attached stylesheet "doit.xsl" does what you requested (<xsl:for-each>) based on Steve's previous comment.
        As you can see stylesheet "doit.2.xsl" does the same, but without the "imperative style" <xsl:for-each> statement.
        
        $ echo 
        "<str>approles=(test1,test2,test3,test4)</str>" | coproc2 doit.xsl - http:
        //datapower1.boeblingen.de.ibm.com:2223 test1 test2 test3 test4 $ $ echo 
        "<str>approles=(test1,test2,test3,test4)</str>" | coproc2 doit.2.xsl - http:
        //datapower1.boeblingen.de.ibm.com:2223 test1 test2 test3 test4 $ $ cat doit.2.xsl <xsl:stylesheet version=
        "1.0" xmlns:xsl=
        "http://www.w3.org/1999/XSL/Transform" xmlns:str=
        "http://exslt.org/strings" > <xsl:template match=
        "/"> <xsl:variable name=
        "seq" select=
        "substring-before(substring-after(., '('), ')')"/>   <xsl:apply-templates mode=
        "output" select=
        "str:tokenize($seq,',')"/> </xsl:template>   <xsl:template match=
        "token" mode=
        "output"> <xsl:value-of select=
        "."/><xsl:text>
        </xsl:text> </xsl:template>   </xsl:stylesheet> $
        


        Hermann<myXsltBlog/> <myXsltTweets/>

        Attachments

  • Nivast
    Nivast
    25 Posts
    ACCEPTED ANSWER

    Re: XSLT help

    ‏2012-12-17T13:45:50Z  in response to Nivast
    Thank you very much Steve,Hermann,Kn.

    I tried but not able to achive my requirement.
    Here is the sample one iam trying.

    <LDAP-search-results xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:dp="http://www.datapower.com/schemas/management">
    <result>
    <DN>uid=qatdiuser02</DN>
    <attribute-value name="applroles">ws_edm_VehicleLifecycleService_v1_op_GetEntry</attribute-value>
    <attribute-value name="applroles">ATT_Admin</attribute-value>
    <attribute-value name="applroles">ws_edm_dlr_v2_svc</attribute-value>
    <attribute-value name="applroles">ws_edm_dlr_v2_op_GetDealerList</attribute-value>
    </result>
    </LDAP-search-results>

    above xml is dynamic and it will be stored in this variable "appRoles"
    <xsl:variable name="appRoles">
    <xsl:copy-of select="dp:variable('var://context/ldap/auxiliary-attributes')"/>
    </xsl:variable>

    If name="applroles" i want to print the value in the loop and if value contains "ws_edm" i want to store it in the variable.

    Please help me on this.
    • swlinn
      swlinn
      1327 Posts
      ACCEPTED ANSWER

      Re: XSLT help

      ‏2013-01-02T22:41:11Z  in response to Nivast
      Hi Nivast,
      I'm not sure what you mean by "print the value" versus "store it in the variable". Perhaps just log the value with a xsl:message in one case?

      In Hermann's example above, pass into the apply-template

      dp:variable('var://context/ldap/auxiliary-attributes')/LDAP-search-results/result/attribute-value[@name='applroles']
      


      Have a match template that matches on attribute-value, and use a xsl conditional (if, choose) to do whatever you want to do. Sorry I can't be more specific, but I'm guessing at what you want to do.

      Regards,
      Steve
      Updated on 2014-03-25T02:43:47Z at 2014-03-25T02:43:47Z by iron-man