Topic
IC4NOTICE: developerWorks Community will be offline May 29-30, 2015 while we upgrade to the latest version of IBM Connections. For more information, read our upgrade FAQ.
7 replies Latest Post - ‏2013-01-09T18:17:45Z by SystemAdmin
SystemAdmin
SystemAdmin
6772 Posts
ACCEPTED ANSWER

Pinned topic issues with String functions on xml

‏2013-01-08T01:29:43Z |
Hi,
I am trying to do substring function on an xml in context ,but as soon as I call the function xml tags gets lost and only values inside the xml tags are getting displayed.
Below is the xsl.
<xsl:copy-of select="substring($incomingRequest, 1, 100)" />

incomingRequest contains the below xml(sample one).
<root>
<text>Item1</text>
<text>Item2</text>
<text>Item3</text>
<text>Item4</text>
</root>

Result is Item1 Item2 Item3 Item4

<xsl:copy-of select="$incomingRequest" /> gives me the exact same xml as shown above.Please help
Updated on 2013-01-09T18:17:45Z at 2013-01-09T18:17:45Z by SystemAdmin
  • kenhygh
    kenhygh
    1463 Posts
    ACCEPTED ANSWER

    Re: issues with String functions on xml

    ‏2013-01-08T11:37:42Z  in response to SystemAdmin
    That's working as designed, XXX-string() only returns string content, and only operates on the 'text' nodes of the input, not elements.

    Ken
    • HermannSW
      HermannSW
      4501 Posts
      ACCEPTED ANSWER

      Re: issues with String functions on xml

      ‏2013-01-08T13:30:35Z  in response to kenhygh
      You need to serialize the XML, this should do what you want:
      <xsl:variable name="serialized">
        <dp:serialize  select="$incomingRequest" omit-xml-decl="yes"/>
      </xsl:variable>
       
      <xsl:copy-of select="substring($serialize, 1, 100)" />
      


       
      Hermann <myXsltBlog/> <myXsltTweets/>
      Updated on 2014-03-25T02:43:02Z at 2014-03-25T02:43:02Z by iron-man
      • SystemAdmin
        SystemAdmin
        6772 Posts
        ACCEPTED ANSWER

        Re: issues with String functions on xml

        ‏2013-01-08T15:04:27Z  in response to HermannSW
        Hi Hermann,

        How to paste the code like the way you did in this thread. Any URL which has these tips?. Please share.
        --Thanks!
        • swlinn
          swlinn
          1346 Posts
          ACCEPTED ANSWER

          Re: issues with String functions on xml

          ‏2013-01-08T15:22:37Z  in response to SystemAdmin
          You have a start and end tag surrounding the code. The tag is a left curly brace, the word "code", and a right curly brace. An example is shown in the plain text help at the right of the message box when you're entering a message.

          Regards,
          Steve
          • HermannSW
            HermannSW
            4501 Posts
            ACCEPTED ANSWER

            Re: issues with String functions on xml

            ‏2013-01-08T15:46:44Z  in response to swlinn
            As Steve said, use *{​code}*blah*{​code}* and the middle part gets displayed as
            blah
            
            .

            What I did above to NOT make {​code} do what it normally does is inserting a zero width white space (&#8203;) after the opening '{':
            *{&#8203;code}*blah*{&#8203;code}*

            You can imagine that I had to enter "another something" to make the previous line show as it is ...

             
            Hermann <myXsltBlog/> <myXsltTweets/>
            Updated on 2014-03-25T02:42:57Z at 2014-03-25T02:42:57Z by iron-man
            • SystemAdmin
              SystemAdmin
              6772 Posts
              ACCEPTED ANSWER

              Re: issues with String functions on xml

              ‏2013-01-08T16:12:11Z  in response to HermannSW
              
              *Thank you Steve and Hermann!* 
              

              for your tips.
              "
              
              "Thank you!"
              
              "
      • SystemAdmin
        SystemAdmin
        6772 Posts
        ACCEPTED ANSWER

        Re: issues with String functions on xml

        ‏2013-01-09T18:17:45Z  in response to HermannSW
        thanks I was able to fix the issue by serializing the request and using disable-output-escaping="yes" to fix the < issue