Topic
18 replies Latest Post - ‏2014-11-11T09:04:29Z by HermannSW
SystemAdmin
SystemAdmin
6772 Posts
ACCEPTED ANSWER

Pinned topic MPG service - Empty Node

‏2013-01-17T09:19:00Z |
We have MPG a Service, for mainframe back-end, when MF backend return any elements with blank value, DP level its parse and return as empty tag.

For example : If a node is blank for e.g node <Employee> is blank, after DP parse ,it appears as <Employee /> instead of

<Employee></Employee>
Can anybody suggest what needs to be done to genearte <Employee /> instead of
<Employee></Employee>*
Updated on 2013-01-23T13:32:24Z at 2013-01-23T13:32:24Z by SystemAdmin
  • kenhygh
    kenhygh
    1433 Posts
    ACCEPTED ANSWER

    Re: MPG service - Empty Node

    ‏2013-01-17T11:02:44Z  in response to SystemAdmin
    Check out the InfoCenter for the DataPower extensions to <xsl:output>. I haven't used it, but it looks like the added attribute of @dp:expand-empty-elements will do what you want.

    Ken
    • HermannSW
      HermannSW
      4372 Posts
      ACCEPTED ANSWER

      Re: MPG service - Empty Node

      ‏2013-01-17T11:46:46Z  in response to kenhygh
      From the XSLT spec: "The html output method should not output an end-tag for empty elements."
      http://www.w3.org/TR/xslt#section-HTML-Output-Method

      With <xsl:output method="xml"> and empty Employee element you will get <Employee></Employee>.
      With <xsl:output method="html"> and empty Employee element you will get <Employee/>.

      Output method default is determined this way, from http://www.w3.org/TR/xslt#element-output:
      The default for the method attribute is chosen as follows. If
      • the root node of the result tree has an element child,
      • the expanded-name of the first element child of the root node (i.e. the document element) of the result tree has local part html (in any combination of upper and lower case) and a null namespace URI, and
      • any text nodes preceding the first element child of the root node of the result tree contain only whitespace characters,
      then the default output method is html; otherwise, the default output method is xml.

       
      Hermann<myXsltBlog/> <myXsltTweets/>
      • HermannSW
        HermannSW
        4372 Posts
        ACCEPTED ANSWER

        Re: MPG service - Empty Node

        ‏2013-01-17T11:52:01Z  in response to HermannSW
        As Ken mentioned you can have finer granularity control by dp:expand-empty-elements attribute of <xsl:output .../>:
        http://pic.dhe.ibm.com/infocenter/wsdatap/v5r0m0/index.jsp?topic=%2Fcom.ibm.dp.xb.doc%2Fextensionfunctions156.htm

         
        Hermann<myXsltBlog/> <myXsltTweets/>
        • SystemAdmin
          SystemAdmin
          6772 Posts
          ACCEPTED ANSWER

          Re: MPG service - Empty Node

          ‏2013-01-17T14:08:42Z  in response to HermannSW
          Hi kenhygh/HermannSW,

          Thanks for valuable suggestions. i tried with same as you told, but getting internal server error after i used below line in my code.

          <xsl:output method="xml" dp:expand-empty-elements=""/>*

          Please help on this.

          Thanks,
          Asit
          • kenhygh
            kenhygh
            1433 Posts
            ACCEPTED ANSWER

            Re: MPG service - Empty Node

            ‏2013-01-17T14:53:33Z  in response to SystemAdmin
            Well, a good place to start is always the log. What's in there?

            Ken
          • kenhygh
            kenhygh
            1433 Posts
            ACCEPTED ANSWER

            Re: MPG service - Empty Node

            ‏2013-01-17T14:54:20Z  in response to SystemAdmin
            and what does your whole stylesheet look like?
            • SystemAdmin
              SystemAdmin
              6772 Posts
              ACCEPTED ANSWER

              Re: MPG service - Empty Node

              ‏2013-01-18T09:13:20Z  in response to kenhygh
              In my style sheet i used like below

              <xsl:output method="xml" dp:expand-empty-elements="*"/>

              getting error is : Fatal error - invalid qname:*

              Actually, this style sheet created to transform backend- response, also doing some status code mapping and logging etc...

              Thanks,
              Asit
              • kenhygh
                kenhygh
                1433 Posts
                ACCEPTED ANSWER

                Re: MPG service - Empty Node

                ‏2013-01-18T09:55:47Z  in response to SystemAdmin
                You can't use a wildcard. You have to explicitly name each element.

                Ken
                • SystemAdmin
                  SystemAdmin
                  6772 Posts
                  ACCEPTED ANSWER

                  Re: MPG service - Empty Node

                  ‏2013-01-18T10:34:34Z  in response to kenhygh
                  Hi,
                  Ok. i tried as below also not working, its not expanding elements
                  For example:
                  <xsl:output method="xml" dp:expand-empty-elements="Employee,Name"/>
                  <xsl:output method="xml" dp:expand-empty-elements="Employee Name"/>

                  Thanks,
                  Asit
            • SystemAdmin
              SystemAdmin
              6772 Posts
              ACCEPTED ANSWER

              Re: MPG service - Empty Node

              ‏2013-01-18T09:29:41Z  in response to kenhygh
              Hi kenhygh,
              Here is my stylesheet

              <xsl:stylesheet varsion=1.0 xmlns:xsl="www.w3.org/1999/XSL/Transfom"
              xmlns:dp="http://www.datapower.com/extensions" extionsion-element-prefixes="dp">

              <xsl:output method="xml" dp:expand-empty-elements="*"/>
              <xsl:template match="/">
              ....
              <xsl:variable name="response-xml" select="."/>
              .....
              <xsl:variable name="finalResponse">
              ...
              </xsl:variable>

              <xsl:copy-of name="$finalResponse"/>

              </xsl:template>
              </xsl:stylesheet>
              • HermannSW
                HermannSW
                4372 Posts
                ACCEPTED ANSWER

                Re: MPG service - Empty Node

                ‏2013-01-19T10:47:00Z  in response to SystemAdmin
                Hi Asit,

                your <xsl:copy-of ...> misses the required select attribute, you specified name.

                See here how it works:
                
                $ coproc2 Asit.xml.xsl dummy.xml http:
                //dp3-l3:2223 ; echo  <?xml version=
                "1.0" encoding=
                "UTF-8"?> <emptyNode/> $ $ coproc2 Asit.xml.expand.xsl dummy.xml http:
                //dp3-l3:2223 ; echo  <?xml version=
                "1.0" encoding=
                "UTF-8"?> <emptyNode></emptyNode> $ $ diff Asit.xml.xsl Asit.xml.expand.xsl 6c6 <   <xsl:output method=
                "xml"/> --- >   <xsl:output method=
                "xml" dp:expand-empty-elements=
                "emptyNode"/> $ $ cat Asit.xml.xsl <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" > <xsl:output method=
                "xml"/>   <xsl:template match=
                "/"> <xsl:variable name=
                "var"><emptyNode/></xsl:variable>   <xsl:copy-of select=
                "$var/*"/> </xsl:template> </xsl:stylesheet> $
                


                 
                Hermann<myXsltBlog/> <myXsltTweets/>
                • SystemAdmin
                  SystemAdmin
                  6772 Posts
                  ACCEPTED ANSWER

                  Re: MPG service - Empty Node

                  ‏2013-01-23T13:32:24Z  in response to HermannSW
                  Hi HermannSW,
                  Thanks for your input. But in my case problem is XML is dynamic.I'm not sure which element is empty.
                  In that case how should i use below line of code in my stylesheet.
                  dp:expand-empty-elements=""

                  Thanks,
                  Asit
                • dpbuddy
                  dpbuddy
                  35 Posts
                  ACCEPTED ANSWER

                  Re: MPG service - Empty Node

                  ‏2014-11-07T22:47:07Z  in response to HermannSW

                  Hi Hermann,

                      I have the same issue. I am using  dp:expand-empty-elements="element-list" in xsl:output. The below link says this dp function is only applicable when your response is either HTML or XHTML.My question is can we use in case of XML? if so how can I use?

                  http://www-01.ibm.com/support/knowledgecenter/#!/SS9H2Y_7.0.0/com.ibm.dp.xi.doc/output_xsltfunction.html

                   

                  Sorry if I don't understand above explination.

                   

                  Thanks

                  Updated on 2014-11-07T22:48:16Z at 2014-11-07T22:48:16Z by dpbuddy
                  • HermannSW
                    HermannSW
                    4372 Posts
                    ACCEPTED ANSWER

                    Re: MPG service - Empty Node

                    ‏2014-11-08T15:41:27Z  in response to dpbuddy

                    Hi,

                    an empty element "empty" is output by default this way

                    • <empty/> for XML
                    • <empty></empty> for HTML

                    as can be seen below.

                    So  dp:expand-empty-elements  has a meaning only for XML output method because for HTML the elements get expanded output anyway.

                     

                    $ coproc2 identity-xml.xsl empty.xml http://dp2-l3:2223 ; echo
                    <?xml version="1.0" encoding="UTF-8"?>
                    <empty/>
                    $ 
                    $ coproc2 identity-html.xsl empty.xml http://dp2-l3:2223 ; echo
                    <empty></empty>
                    $ 
                    $ cat empty.xml 
                    <empty/>
                    $ 
                    $ cat identity-html.xsl 
                    <xsl:stylesheet version="1.0"
                      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                    >
                      <xsl:output method="html"/>
                    
                      <xsl:template match="/">
                        <xsl:copy-of select="."/>
                      </xsl:template>
                    
                    </xsl:stylesheet>
                    $ 
                    $ diff identity-html.xsl identity-xml.xsl 
                    4c4
                    <   <xsl:output method="html"/>
                    ---
                    >   <xsl:output method="xml"/>
                    $
                    

                     

                    Hermann.

                    Updated on 2014-11-08T15:41:43Z at 2014-11-08T15:41:43Z by HermannSW
                    • dpbuddy
                      dpbuddy
                      35 Posts
                      ACCEPTED ANSWER

                      Re: MPG service - Empty Node

                      ‏2014-11-09T03:23:42Z  in response to HermannSW

                      Hermann,

                          Thanks for quick response

                       I have a scenario where in datapower is self closing the element when it has no value in it ex:<empty/>.How can I send to backend as <empty></empty> when output method="xml"?

                       

                      Thanks,

                      • HermannSW
                        HermannSW
                        4372 Posts
                        ACCEPTED ANSWER

                        Re: MPG service - Empty Node

                        ‏2014-11-09T09:19:49Z  in response to dpbuddy

                        Hi,

                        as said above the self-closing in case of <xsl:output>'s @method being "xml" is per spec.

                        The only way to do what you want with that output method is to list all elements you do not want to collapse in xsl:output's  dp:expand-empty-elements="...".

                        In case you do not know the list upfront, you cannot do (in single stylesheet) what you want with "xml" method and would need to switch to "html" method, but that would expand each and every empty node.

                        Again, this behavior is part of the XSLT 1.0 spec (... The html output method should not output an end-tag for empty elements. ...) and implemented by DataPower only.


                        <dynamic>There is one option left in case you have a criterion on dynamically deciding which empty nodes you want expanded output for: You can generate a "new" stylesheet listing all those nodes in  dp:expand-empty-elements  into a context and then run the transform referencing the new stylesheet in that context, either by another xform action, or via  dp:transform()  in the stylesheet.</dynamic>


                        Hermann.

                        Updated on 2014-11-09T09:36:53Z at 2014-11-09T09:36:53Z by HermannSW
                        • dpbuddy
                          dpbuddy
                          35 Posts
                          ACCEPTED ANSWER

                          Re: MPG service - Empty Node

                          ‏2014-11-10T21:05:08Z  in response to HermannSW

                          Hermann,

                             Thanks for the quick reply.

                           I know list of all elements.

                           I don't know somehow still I am not able to get expanded elements in my output.Below I ahve given my xslt.I might be missing some elements in my xslt.

                          xslt:

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

                          <xsl:stylesheetversion="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" dp:expand-empty-elements="a script"/>

                          <xsl:template match="/">

                          <xsl:copy-of select="."/>

                          </xsl:template>

                          </xsl:stylesheet>

                           

                          xml:

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

                          <info>

                          <script/>

                          <a/>

                          <com>IBM</com>

                          </info>

                           

                           

                          Thanks,

                           

                           

                          Updated on 2014-11-10T21:11:53Z at 2014-11-10T21:11:53Z by dpbuddy
                          • HermannSW
                            HermannSW
                            4372 Posts
                            ACCEPTED ANSWER

                            Re: MPG service - Empty Node

                            ‏2014-11-11T09:04:29Z  in response to dpbuddy

                            Hi,

                            your stylesheet DOES work, see below.

                            BUT you will have to set output of the xform action to OUTPUT.

                            If you store stylesheet output into a context and then send that context to OUTPUT by a Results action, the Results action will serialize the (parsed) XML of context and it does not know about which elements you want to be expanded.

                            $ coproc2 dpbuddy.xsl dpbuddy.xml http://dp2-l3:2223; echo
                            <?xml version="1.0" encoding="UTF-8"?>
                            <info>
                            <script></script>
                            <a></a>
                            <com>IBM</com>
                            </info>
                            $
                            


                            Hermann.

                            Updated on 2014-11-11T09:05:58Z at 2014-11-11T09:05:58Z by HermannSW