Topic
  • 7 replies
  • Latest Post - ‏2013-01-09T18:17:45Z by SystemAdmin
SystemAdmin
SystemAdmin
6772 Posts

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
    1607 Posts

    Re: issues with String functions on xml

    ‏2013-01-08T11:37:42Z  
    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
    4874 Posts

    Re: issues with String functions on xml

    ‏2013-01-08T13:30:35Z  
    • kenhygh
    • ‏2013-01-08T11:37:42Z
    That's working as designed, XXX-string() only returns string content, and only operates on the 'text' nodes of the input, not elements.

    Ken
    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

    Re: issues with String functions on xml

    ‏2013-01-08T15:04:27Z  
    • HermannSW
    • ‏2013-01-08T13:30:35Z
    You need to serialize the XML, this should do what you want:
    <pre class="java dw" data-editor-lang="java" data-pbcklang="java" dir="ltr"><xsl:variable name="serialized"> <dp:serialize select="$incomingRequest" omit-xml-decl="yes"/> </xsl:variable> <xsl:copy-of select="substring($serialize, 1, 100)" /> </pre>

     
    Hermann <myXsltBlog/> <myXsltTweets/>
    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
    1348 Posts

    Re: issues with String functions on xml

    ‏2013-01-08T15:22:37Z  
    Hi Hermann,

    How to paste the code like the way you did in this thread. Any URL which has these tips?. Please share.
    --Thanks!
    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
    4874 Posts

    Re: issues with String functions on xml

    ‏2013-01-08T15:46:44Z  
    • swlinn
    • ‏2013-01-08T15:22:37Z
    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
    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

    Re: issues with String functions on xml

    ‏2013-01-08T16:12:11Z  
    • HermannSW
    • ‏2013-01-08T15:46:44Z
    As Steve said, use *{​code}*blah*{​code}* and the middle part gets displayed as <pre class="java dw" data-editor-lang="java" data-pbcklang="java" dir="ltr">blah </pre> .

    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/>
    
    *Thank you Steve and Hermann!* 
    

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

    Re: issues with String functions on xml

    ‏2013-01-09T18:17:45Z  
    • HermannSW
    • ‏2013-01-08T13:30:35Z
    You need to serialize the XML, this should do what you want:
    <pre class="java dw" data-editor-lang="java" data-pbcklang="java" dir="ltr"><xsl:variable name="serialized"> <dp:serialize select="$incomingRequest" omit-xml-decl="yes"/> </xsl:variable> <xsl:copy-of select="substring($serialize, 1, 100)" /> </pre>

     
    Hermann <myXsltBlog/> <myXsltTweets/>
    thanks I was able to fix the issue by serializing the request and using disable-output-escaping="yes" to fix the < issue