Topic
3 replies Latest Post - ‏2013-05-17T16:07:21Z by swlinn
DSoa
DSoa
2 Posts
ACCEPTED ANSWER

Pinned topic Problem with setvar output type XML

‏2013-05-16T18:04:38Z |

I am having a problem with saving a context to a variable as XML and then processing the value of the variable in a stylesheet.  If the data from the context doesn't include a <?xml ?> prolog, the processing in my stylesheet fails.  If I add an identity transform action before the setvar just going from context to the same context, it works.

Here's more details.

The context I'm processing is coming from a backend service after a results action.  In this case, the context is INPUT.  I am storing it in a variable called var://context/MYCONTEXT/myresults.  I have the Output Type specified as XML.

In a transform rule, I am processing all the variables in MYCONTEXT and creating a new XML document from them.  The snippet of code looks like this:

<xsl:template match="/">
       <xsl:variable name="inputContextName" select="dp:variable('var://service/multistep/input-context-name')"/>
       <xsl:variable name="contextVariables" select-"dp:variable(concat('var://context/', $inputContextName, '/_extension/variables'))"/>
       <xsl:variable name="allVars">
            <vars>
                <xsl:for-each select="$contextVariables/variables/variable/text()">
                    <xsl:variable name="fullVarName" select="."/>
                    <xsl:element name="record">
                        <xsl:copy-of select="dp:variable($fullVarName)"/>
                    </xsl:element>
                </xsl:for-each>
            </vars>
        </xsl:variable>

If the data written to the variable in the setvar did not include a <?xml ?> prolog, I get <record>store:///notfound</record> in the result.

If I process the INPUT context with a stylesheet, I can get the value as XML fine, or if insert an identity transform from INPUT to INPUT like I mentioned, it works fine.  I am trying to avoid having to add extra actions like this when it seems like it should work to write it to a variable with Output Type XML.

Thanks.

  • swlinn
    swlinn
    1344 Posts
    ACCEPTED ANSWER

    Re: Problem with setvar output type XML

    ‏2013-05-16T21:37:03Z  in response to DSoa

    I believe some actions do an implicit parse on the input context, transform action being one of them, so if your data is XML but for some reason is not recognized as a node set because it has not been parsed yet (perhaps a non-XML response on the service??) and you pass it into an action that does not do an implicit parse, my guess set variable being one of them that does not, then you'll get an error.  By doing the identity transformation you are adding a parse in addition to copying the output to an output context, so the set variable gets a XML nodeset with that context, not a string. 

    Regards,

    Steve

    • DSoa
      DSoa
      2 Posts
      ACCEPTED ANSWER

      Re: Problem with setvar output type XML

      ‏2013-05-17T14:56:31Z  in response to swlinn

      I understand what it is doing, but does it make sense?  What is the point of specifying an XML Output Type for SetVar if it doesn't store the result as a nodeset?  If you look in the probe for a variable containing XML, it shows as a nodeset.  Data without an XML prolog shows as 'store:///notfound'.  So my point is why the inconsistency with handling XML data across different actions?

      And more importantly, is there a way to fix the problem without resorting to identity transformations?

      Thanks.

      • swlinn
        swlinn
        1344 Posts
        ACCEPTED ANSWER

        Re: Problem with setvar output type XML

        ‏2013-05-17T16:07:21Z  in response to DSoa

         I know you can have a string of valid XML, but if that data isn't converted into an XML NodeSet/DOM structure internally, an action expecting this  will fail if that action does not implicitly attempt to parse the string into a nodeset.  I don't believe the output type of XML does anything to parse the input context.  Since I am not in the development organization I can't speak to the history or "whys" of the implementation. You can always open a request for enhancement at http://www.ibm.com/developerworks/rfe/?PROD_ID=577.  I'm sorry, but I don't see a way today to do the parsing of an unparsed XML string into a nodeset for the set variable action without an identity transformation preceeding it.

        Regards,
        Steve