Skip to Content
author's profile photo Former Member
Former Member

XSL

Hi

I am trying to use an xslt stylesheet to sort my idoc segments but cannot get it to work. I am not getting any errors and I am getting an output but the sorting is not happening.

Here is my code

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
   <xsl:template match="/ANYIDOC/IDOC">
      <ns1:ANYIDOC xmlns:ns1="urn:sap-com:document:sap:idoc:messages">
        
            <ns1:IDOC>
	<xsl:for-each select=".">
	<xsl:sort select="SEG1/FIELD1"/>
               	<xsl:copy-of select="SEG1"/>
	</xsl:for-each>
            </ns1:IDOC>
        

      </ns1:ANYIDOC>
   </xsl:template>
</xsl:stylesheet>

As you can see I am trying to sort the SEG1 segments using the FIELD1 field within the SEG1 segment.

I hope you can help.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

5 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Sep 12, 2011 at 06:56 PM

    Hi,

    Sorry no joy yet.... Could anybody please suggest a way to make this sort function work please?

    Thanks

    SA

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Thanks SA.

      Good that your issue got solved.

      We were using wrong function to get the node contents. We should have used current() which is the function returns a node-set that contains only the current node.

      Peter's code is good though. I would recommend it.

      @Peter: Thanks for sharing, i updated with your knowledge piece.

      Regards

      Ramesh

  • author's profile photo Former Member
    Former Member
    Posted on Sep 13, 2011 at 06:43 AM

    Thank you Peter...

    So you are saying that your version would be more performant?

    Sorry I ran out of 6 points to give so only assigned 2... I will assign more if it allows me on your reply.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Sep 12, 2011 at 04:04 PM
    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 12, 2011 at 04:12 PM

    Hi,

    Even i tried in XML Spy, i am also getting blank.

    But for temporary solution you can use

    <xsl:value-of select="">

    for each element. This is working for me.

    Let me see if copy works, i will let you know.

    regards

    Ramesh

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Ramesh,

      Would you mind posting the entire code solution you are using as I am still unable to get this to work.

      I am now using the following and it is the sort tag that causes it to give nothing... when yo take it away you get the result but not sorted...

      <?xml version="1.0" encoding="UTF-8"?>
      <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      
      
       <xsl:template match="/ANYIDOC/IDOC">
            <ns1:ANYIDOC xmlns:ns1="urn:sap-com:document:sap:idoc:messages">
                     <xsl:for-each select=".">
      <xsl:sort select="/SEG1/FIELD1">
      <ns1:IDOC>
                        <xsl:copy-of select="SEG1"/>
                     </ns1:IDOC>
      </xsl:sort>
      </xsl:for-each>
      
            </ns1:ANYIDOC>
         </xsl:template>
      
      
      
      </xsl:stylesheet>

  • author's profile photo Former Member
    Former Member
    Posted on Sep 12, 2011 at 04:39 PM
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
       <xsl:template match="/ANYIDOC/IDOC">
          <ns1:ANYIDOC xmlns:ns1="urn:sap-com:document:sap:idoc:messages">
            
                <ns1:IDOC>
    	<xsl:for-each select=".">
    	<xsl:sort select="SEG1/FIELD1"/>
    	<xsl:copy-of select="node()"/>
    	</xsl:for-each>
                </ns1:IDOC>
            
     
          </ns1:ANYIDOC>
       </xsl:template>
    </xsl:stylesheet>

    Try node() function as explained above

    Try the above changes

    Edited by: Ramesh P on Sep 12, 2011 10:13 PM

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.