Topic
  • 5 replies
  • Latest Post - ‏2013-07-31T01:36:07Z by tim3208
tim3208
tim3208
5 Posts

Pinned topic XSLT and the ampersand

‏2013-07-25T03:23:21Z |

Greetings,

I am fairly new to datapower and I am stumped by a problem with the "&" character. We have a SOAP service with a consumer who insists on using the & in their requests. For example one of their fields could be <CUSTOMER-LAST-NAME>Jones & Sons</CUSTOMER-LAST-NAME> Unfortunately, the service provider is unable to handle special characters in the fields. I was trying to come up with a way in DataPower to change the "&" into something the provider could handle. My first instinct was to use a transform action, but even if the logic in the transform action is empty I get the following error:

implied action Parse input as SOAP, attempt pipeline failed: illegal character ' ' at line 9 of http://xx.xx.xx.xx:nnnn/myServiceNameUrl

Any help appreciated

Tim

  • HermannSW
    HermannSW
    4654 Posts
    ACCEPTED ANSWER

    Re: XSLT and the ampersand

    ‏2013-07-26T12:27:16Z  
    • tim3208
    • ‏2013-07-25T18:46:44Z

    Thanks David,

    I manged to get it working without & character. however if I add & to one of the fields the Transform Binary action in the non-xml based MPG errors with the following:

    request SandboxNonXml_SoapMpg_rule #1 xformbin: 'Transforming (possibly binary) INPUT with local:///requestTransformer.xsl results stored in dpvar_1' failed: illegal character ' ' at offset 458 of http://10.69.102.107:7200/TpicDefaultSvc/TpicCXTService.svc

    illegal character ' ' at offset 458 of http://xx.xx.xx.xx:nnnn/myServiceNameUrl

    The guts of the XSL are:

    <xsl:template match="@* | node()">
          <xsl:copy>
            <xsl:apply-templates select="@* | node()"/>
           </xsl:copy>
        </xsl:template>

    <xsl:template match="@*|text()|comment()|processing-instruction">
          <xsl:copy-of select="translate(.,'Test','ABCDEFGHIJK')"/>
    </xsl:template>
    </xsl:stylesheet>

     

    Thanks

    Tim

    Hi Tim,

    as the others already mentioned, your input is Non-XML.

    Reason is that ampersand character (as well as less than character) ALWAYS have to be escaped in XML text, see 2nd paragraph of spec:
    http://www.w3.org/TR/REC-xml/#syntax

    Next, if you have a Non-XML service you cannot use "normal" stylesheets for processing.
    You may want to look into these 2 WSTE webcasts on Non-XML data processing in stylesheets (.pdf, .mp3 and Samples.zip):
    http://www-01.ibm.com/support/docview.wss?uid=swg27022977
    http://www-01.ibm.com/support/docview.wss?uid=swg27022979

    For your specific problem I posted and attached a solution (ampify.xsl) back in 2011:
    https://www.ibm.com/developerworks/community/forums/html/topic?id=77777777-0000-0000-0000-000014675413#77777777-0000-0000-0000-000014675880

    ampify.xsl just replaces ALL "&" charcters by "&amp;" ...

     

    Was a bit difficult to find since forum search for stuff before April this year is still broken ... :-(

    But with help of google search and then tracking all new threads from August 2011 it was possible.


    Hermann<myXsltBlog/> <myXsltTweets/> <myCE/>

    Updated on 2013-07-26T12:28:55Z at 2013-07-26T12:28:55Z by HermannSW
  • SatheshSubramaniam
    SatheshSubramaniam
    12 Posts

    Re: XSLT and the ampersand

    ‏2013-07-25T04:12:12Z  

    hi tim,

    if your request type is xml or soap then u will get this error. because Some characters have a special meaning in XML. DataPower will throw error. you have to use &amp; instead of &

    CUSTOMER-LAST-NAME>Jones & Sons</CUSTOMER-LAST-NAME> should be CUSTOMER-LAST-NAME>Jones &amp; Sons</CUSTOMER-LAST-NAME>

    or change the request type

    use following link to get the syntax:

    http://www.w3schools.com/xml/xml_syntax.asp

  • David07
    David07
    73 Posts

    Re: XSLT and the ampersand

    ‏2013-07-25T04:52:31Z  

    Hi Tim,

    As sathesh said while sending request itself you want to change the '&' to '&amp', otherwise if you want to handle this issue in datapower means then you want set the Request type to Non-xml. So datapower will accept any type of message and in processing policy using stylesheet change the '&' to the format service provider supporting.

    here is the code for translation,

    xpath function,

     translate(., '&', 'anystring')"

     

    Thanks,

    David.

  • tim3208
    tim3208
    5 Posts

    Re: XSLT and the ampersand

    ‏2013-07-25T18:46:44Z  
    • David07
    • ‏2013-07-25T04:52:31Z

    Hi Tim,

    As sathesh said while sending request itself you want to change the '&' to '&amp', otherwise if you want to handle this issue in datapower means then you want set the Request type to Non-xml. So datapower will accept any type of message and in processing policy using stylesheet change the '&' to the format service provider supporting.

    here is the code for translation,

    xpath function,

     translate(., '&', 'anystring')"

     

    Thanks,

    David.

    Thanks David,

    I manged to get it working without & character. however if I add & to one of the fields the Transform Binary action in the non-xml based MPG errors with the following:

    request SandboxNonXml_SoapMpg_rule #1 xformbin: 'Transforming (possibly binary) INPUT with local:///requestTransformer.xsl results stored in dpvar_1' failed: illegal character ' ' at offset 458 of http://10.69.102.107:7200/TpicDefaultSvc/TpicCXTService.svc

    illegal character ' ' at offset 458 of http://xx.xx.xx.xx:nnnn/myServiceNameUrl

    The guts of the XSL are:

    <xsl:template match="@* | node()">
          <xsl:copy>
            <xsl:apply-templates select="@* | node()"/>
           </xsl:copy>
        </xsl:template>

    <xsl:template match="@*|text()|comment()|processing-instruction">
          <xsl:copy-of select="translate(.,'Test','ABCDEFGHIJK')"/>
    </xsl:template>
    </xsl:stylesheet>

     

    Thanks

    Tim

  • HermannSW
    HermannSW
    4654 Posts

    Re: XSLT and the ampersand

    ‏2013-07-26T12:27:16Z  
    • tim3208
    • ‏2013-07-25T18:46:44Z

    Thanks David,

    I manged to get it working without & character. however if I add & to one of the fields the Transform Binary action in the non-xml based MPG errors with the following:

    request SandboxNonXml_SoapMpg_rule #1 xformbin: 'Transforming (possibly binary) INPUT with local:///requestTransformer.xsl results stored in dpvar_1' failed: illegal character ' ' at offset 458 of http://10.69.102.107:7200/TpicDefaultSvc/TpicCXTService.svc

    illegal character ' ' at offset 458 of http://xx.xx.xx.xx:nnnn/myServiceNameUrl

    The guts of the XSL are:

    <xsl:template match="@* | node()">
          <xsl:copy>
            <xsl:apply-templates select="@* | node()"/>
           </xsl:copy>
        </xsl:template>

    <xsl:template match="@*|text()|comment()|processing-instruction">
          <xsl:copy-of select="translate(.,'Test','ABCDEFGHIJK')"/>
    </xsl:template>
    </xsl:stylesheet>

     

    Thanks

    Tim

    Hi Tim,

    as the others already mentioned, your input is Non-XML.

    Reason is that ampersand character (as well as less than character) ALWAYS have to be escaped in XML text, see 2nd paragraph of spec:
    http://www.w3.org/TR/REC-xml/#syntax

    Next, if you have a Non-XML service you cannot use "normal" stylesheets for processing.
    You may want to look into these 2 WSTE webcasts on Non-XML data processing in stylesheets (.pdf, .mp3 and Samples.zip):
    http://www-01.ibm.com/support/docview.wss?uid=swg27022977
    http://www-01.ibm.com/support/docview.wss?uid=swg27022979

    For your specific problem I posted and attached a solution (ampify.xsl) back in 2011:
    https://www.ibm.com/developerworks/community/forums/html/topic?id=77777777-0000-0000-0000-000014675413#77777777-0000-0000-0000-000014675880

    ampify.xsl just replaces ALL "&" charcters by "&amp;" ...

     

    Was a bit difficult to find since forum search for stuff before April this year is still broken ... :-(

    But with help of google search and then tracking all new threads from August 2011 it was possible.


    Hermann<myXsltBlog/> <myXsltTweets/> <myCE/>

    Updated on 2013-07-26T12:28:55Z at 2013-07-26T12:28:55Z by HermannSW
  • tim3208
    tim3208
    5 Posts

    Re: XSLT and the ampersand

    ‏2013-07-31T01:36:07Z  
    • HermannSW
    • ‏2013-07-26T12:27:16Z

    Hi Tim,

    as the others already mentioned, your input is Non-XML.

    Reason is that ampersand character (as well as less than character) ALWAYS have to be escaped in XML text, see 2nd paragraph of spec:
    http://www.w3.org/TR/REC-xml/#syntax

    Next, if you have a Non-XML service you cannot use "normal" stylesheets for processing.
    You may want to look into these 2 WSTE webcasts on Non-XML data processing in stylesheets (.pdf, .mp3 and Samples.zip):
    http://www-01.ibm.com/support/docview.wss?uid=swg27022977
    http://www-01.ibm.com/support/docview.wss?uid=swg27022979

    For your specific problem I posted and attached a solution (ampify.xsl) back in 2011:
    https://www.ibm.com/developerworks/community/forums/html/topic?id=77777777-0000-0000-0000-000014675413#77777777-0000-0000-0000-000014675880

    ampify.xsl just replaces ALL "&" charcters by "&amp;" ...

     

    Was a bit difficult to find since forum search for stuff before April this year is still broken ... :-(

    But with help of google search and then tracking all new threads from August 2011 it was possible.


    Hermann<myXsltBlog/> <myXsltTweets/> <myCE/>

    Thanks Hermann. Perfect

    That seems to do the trick. Thanks also for the links to the webcasts.