Topic
  • 3 replies
  • Latest Post - ‏2013-04-18T08:18:00Z by HermannSW
Jaango
Jaango
267 Posts

Pinned topic String processing

‏2013-04-16T11:59:12Z |

I want to serialize the xml, which will convert all '<' to &lt ; , then put the string, within the variable strin, under element a. The value of string should come as is while setting the header. This combination is set as request header, for processing at backend. However, unable to keep the exact value of string in the header. I left a space between l/g t and ; so that formatting is not lost

My xslt
{code}
<xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exsl="http://exslt.org/common" xmlns:xalan="http://xml.apache.org/xslt" xmlns:regexp="http://exslt.org/regular-expressions" xmlns:dp="http://www.datapower.com/extensions" xmlns:fn="http://www.w3.org/2005/xpath-functions" exclude-result-prefixes="xalan dp exsl" extension-element-prefixes="dp regexp fn">
 <xsl:template match="/">
  <xsl:variable name="strin" select="'&lt ;&gt ;'"/>
  <xsl:variable name="xml">
   <b>
    <a/>
   </b>
  </xsl:variable>
  <xsl:variable name="seri">
   <dp:serialize select="$xml" omit-xml-decl="yes"/>
  </xsl:variable>
  <xsl:variable name="bef" select="substring-before($seri,'&lt ;a')"/>
  <xsl:variable name="aft" select="substring-after($seri,'a/>')"/>
  <xsl:variable name="complete" select="concat($bef,'&lt ;a>',$strin,'&lt ;/a>',$aft)"/>
  <dp:set-request-header name="'sampleHeader'" value="$complete"/>
  <xsl:copy-of select="dp:request-header('sampleHeader')"/>
 </xsl:template>
</xsl:stylesheet>

 

C:\Program Files\Java\jre1.6.0_20\bin>java coproc2 string.xsl ab.xml http://mybox:2223

{code}


My actual output header
{code}
&lt ;b>&lt ;a>&lt ;>&lt ;/a>&lt ;/b>
{code}

 

My expected output header
{code}
&lt ;b>&lt ;a>&lt ;&gt ;&lt ;/a>&lt ;/b>
{code}

  • HermannSW
    HermannSW
    4866 Posts

    Re: String processing

    ‏2013-04-17T21:01:11Z  

    Hi Maneesh,

    unfortunately the {code}...{code} sections have been "stolen" by Forum software migration ... :-(

    Can you please attach a text file containing the actual and expected values?


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


     

  • Jaango
    Jaango
    267 Posts

    Re: String processing

    ‏2013-04-18T01:46:38Z  
    • HermannSW
    • ‏2013-04-17T21:01:11Z

    Hi Maneesh,

    unfortunately the {code}...{code} sections have been "stolen" by Forum software migration ... :-(

    Can you please attach a text file containing the actual and expected values?


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


     

    Sure Hermann. here it is.

    Attachments

  • HermannSW
    HermannSW
    4866 Posts

    Re: String processing

    ‏2013-04-18T08:18:00Z  
    • Jaango
    • ‏2013-04-18T01:46:38Z

    Sure Hermann. here it is.

    Hi Maneesh,

    please do not rely on "dp:request-header()" for verifying what you are doing.

    The <xsl:copy-of> changes what is really present in header.

    Here you can see what your stylesheet currenty really does:

    $ coproc2 lt.xsl lt.xsl http://dp2-l3:2223 -v ; echo
    * About to connect() to dp2-l3 port 2223 (#0)
    *   Trying 9.152.92.59... connected
    * Connected to dp2-l3 (9.152.92.59) port 2223 (#0)
    > POST / HTTP/1.1
    ...

    > Content-Type: application/x-www-form-urlencoded
    > Expect: 100-continue
    >
    < HTTP/1.1 100 Continue
    < X-Note: Gateway Ack
    < HTTP/1.1 200 OK
    < X-Backside-Transport: FAIL FAIL
    < Connection: Keep-Alive
    < Transfer-Encoding: chunked
    < sampleHeader: <b><a><></a></b>
    < Content-Type: text/xml
    <
    * Connection #0 to host dp2-l3 left intact
    * Closing connection #0
    &lt;b>&lt;a>&lt;>&lt;/a>&lt;/b>
    $

     

    It generates Non-XML -- both characters (less than as well as greater than) are unescaped in sampleHeader.
    I had to add

    <dp:set-response-header name="'sampleHeader'" value="$complete"/>

    in order to make coproc2 show the effect -- coproc2 is based on curl and "-v" option gives verbose output.


    Adding this and using "$strin3" instead of "$strin" in defining $complete does what you want:

    <xsl:variable name="strin2" select="regexp:replace($strin,'&lt;','','&amp;lt;')"/>
    <xsl:variable name="strin3" select="regexp:replace($strin2,'&gt;','','&amp;gt;')"/>


    Here you can see that is really works:

    $ coproc2 lt2.xsl lt.xsl http://dp2-l3:2223 -v 2>&1 | grep sampleHeader
    < sampleHeader: <b><a>&lt;&gt;</a></b>
    $


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