Dynamically sorting using XSL

Results 1 to 2 of 2

Thread: Dynamically sorting using XSL

  1. #1
    Join Date
    Dec 1969

    Default Dynamically sorting using XSL

    I&#039;ve been attempting to make an XSL Stylesheet that uses dynamic sorting. Currently the sorting works if I hardcode the element to sort by, but I want it to be dynamic depending on the data coming from the XML file.<BR><BR>So I&#039;m declaring a variable that holds the sort element name from the XML file:<BR>&#060;xsl:variable name="sortby" select="results/setup/sortby" /&#062;<BR><BR>Then I attempt to pass that variable to the xsl:sort element:<BR>&#060;xsl:sort select="$sortby" order="ascending" data-type="number" /&#062;<BR><BR>It doesn&#039;t seem to work and I can&#039;t figure out why. Does anyone know how to pass the sort element dynamically?<BR><BR>Thanks!<BR><BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: Dynamically sorting using XSL

    In the XSL file, I have a parameter:<BR>&#060;xsl:param name="sort" select="&#039;StudyId&#039;" /&#062;<BR><BR>The select part of that is the default field that you wish to sort by.<BR><BR>Then, when I apply a particular template, I specify the sort that I wish to use:<BR> &#060;xsl:apply-templates select="./Study"&#062;<BR> &#060;xsl:sort select="./*[local-name() = $sort]" order="ascending"/&#062;<BR> &#060;/xsl:apply-templates&#062;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts