XSL Sort tables in a parent table


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 11 of 11

Thread: XSL Sort tables in a parent table

  1. #1
    Join Date
    Feb 2011
    Posts
    5

    XSL Sort tables in a parent table

    Hello !

    Please, I need an XSL file sample to sort TABLES in a parent Table.

    Thanks for any help !

  2. #2
    Join Date
    Oct 2008
    Posts
    142

    sorting xml

    hi there,

    if you plan to use xpath with xslt then look at xsl:sort
    --> http://www.google.com/#hl=en&sugexp=...d06a33501ac671

    you could use xpath and for example vb or csharp to do your sorting and then write html output.

    it really depends on how you plan to do this task.

    best regards,

    tonci korsano

  3. #3
    Join Date
    Feb 2011
    Posts
    5
    Yes - but how to use it for sorting TABLES ? I searched over the internet, I found xsl:sort, this is a trivial task for sorting RECORDS.
    BUT I have to sort TABLES, not RECORDS !!
    Any sample code is welcome !
    Thank you anyway!

  4. #4
    Join Date
    Oct 2008
    Posts
    142

    maybe this will help

    hi there,

    look at this example:

    Code:
    <xsl:param name="sortDirection" select="'descending'"/>
    <xsl:param name="sortType" select="'text'" />
        <xsl:template match="*">
        	<xsl:apply-templates>
    			<xsl:sort select="@*[name()=$sortBy]" data-type="{$sortType}" order="{$sortDirection}" />
    		</xsl:apply-templates>
    	</xsl:template>
    in this example, i sort with variables.
    match="*" applies to the whole dataset.
    select="@*[name()=$sortBy]" applies a sort criteria by an attribute specified in parameter $sortBy.
    data-type="{$sortType}" specifies the data type of this sort operation, which is specified in a parameter.
    order="{$sortDirection}" specifies the direction, which again is passed by a parameter.
    this file is called PlayerPerfomanceSort.xslt,
    i call this xslt file for a transformation in a very old asp.net web page (not used anymore in a really long time).
    i am submitting in case it might help.

    Code:
        Protected Sub sortXML(ByVal field As String, ByVal direction As String, ByVal dataType As String)
            'sort last stored procedure output without calling the corresponding stored procedure
            'tks oct.21.2008
    
            Dim XMLDoc As New XmlDocument
            Dim XSLTDoc As XslTransform
            Dim endT As New DateTime(CInt(EndDate.SelectedDate.Year.ToString), CInt(EndDate.SelectedDate.Month.ToString), CInt(EndDate.SelectedDate.Day.ToString), 23, 59, 59)
            Dim startT As New DateTime(CInt(StartDate.SelectedDate.Year.ToString), CInt(StartDate.SelectedDate.Month.ToString), CInt(StartDate.SelectedDate.Day.ToString), 0, 0, 0)
            Try
    
                XMLDoc = Session("pp.xml")
    
                Dim sw As StringWriter = New StringWriter
                Dim XsltParams As New XsltArgumentList
                XsltParams.AddParam("sortBy", "", field)
                XsltParams.AddParam("sortDirection", "", direction)
                XsltParams.AddParam("sortType", "", dataType)
    
                XSLTDoc = New XslTransform
    
                XSLTDoc.Load(Server.MapPath("PlayerPerfomanceSort.xslt"))
                XSLTDoc.Transform(XMLDoc, XsltParams, sw, Nothing)
    
                ResultTable.InnerHtml = sw.ToString()
    
            Catch ex As Exception
    
            End Try
    
        End Sub
    that's it.

    best regards,

    tonci korsano

  5. #5
    Join Date
    Feb 2011
    Posts
    5
    Thank you very much !

  6. #6
    Join Date
    Feb 2011
    Posts
    5
    It seems that this sorting pocedure works for sorting a field, not children Tables of an another table. I need to sort tables !

    this:
    <ParentTable id="1" >
    <coAsig tip="S"></coAsig>
    <asigD D_1="B1114"></asigD>
    <asigB1 B1_1="1" ></asigB1>
    <asigB2 B2_1="0" ></asigB2>
    <asigB3 B3_1="10"></asigB3>
    <asigB4 B4_1="11" ></asigB4>
    </ParentTable >

    must be:

    <ParentTable id="1" >
    <asigB1 B1_1="1" ></asigB1>
    <asigB2 B2_1="0" ></asigB2>
    <asigB3 B3_1="10"></asigB3>
    <asigB4 B4_1="11" ></asigB4>
    <asigD D_1="B1114"></asigD>
    <coAsig tip="S"></coAsig>
    </ParentTable >

  7. #7
    Join Date
    May 2009
    Location
    United Kingdom
    Posts
    49

  8. #8
    Join Date
    Feb 2011
    Posts
    5
    Thank you very much both tkorsano and reedy837 !!!

  9. #9
    Join Date
    Feb 2011
    Posts
    5
    Hello !

    Yours code works but it does not return the same xml !

    I want a code to return the SAME XML but sorted.

    Thank you !

    PS. I found samples that returns different formats on output. I want that the output to be the same with the imput, but with elements sorted by their names

  10. #10
    Join Date
    May 2009
    Posts
    60
    Which parser or browser do you use

    I saw you use IE Browser
    so you can not create an outputfile


    when you use a parser you can write a new xml file

    e.g
    saxon

    java -mx250m -ms250m -cp saxon9he.jar;xercesImpl-2.9.1.jar net.sf.saxon.Transform -x:org.apache.xerces.parsers.SAXParser -o:xml-file.xml -s:xml-file.xml -xsl:xsl-file.xml
    so you overwrite the input xml-file

    Browser are viewer of xml files
    wiht css , xsl and xsl:fo you can change the form of display

  11. #11
    Join Date
    Oct 2008
    Posts
    142

    blog about sorting xml with xslt transformation and .net framework

    hi there,

    i wrote a blog about this sorting xml topic.
    it is about a reply i made to this discussion.
    it is in the following link http://dotnetflux.blogspot.com/2011/...eters-and.html
    it contains an example with explanation of how to sort xml data, and how to transform this sorted xml data into formatted html.
    this example uses xslt and visual basic .net.

    good luck,

    tonci.

Similar Threads

  1. Replies: 1
    Last Post: 07-25-2005, 09:00 AM
  2. Re: (No subject)
    By Joe in forum Database
    Replies: 0
    Last Post: 04-04-2003, 05:13 PM
  3. SQL Many Table Relation
    By sa in forum .NET
    Replies: 2
    Last Post: 08-07-2002, 02:20 PM
  4. sorting multiple tables in xsl
    By Brian Zomchek in forum XML
    Replies: 0
    Last Post: 07-18-2001, 05:20 PM
  5. XML & XSL = HTML (well sort of)
    By rob in forum XML
    Replies: 5
    Last Post: 02-20-2001, 02:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center