Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. XML / XSL
  4. XSL and Params with Sort-By [modified]

XSL and Params with Sort-By [modified]

Scheduled Pinned Locked Moved XML / XSL
xmltutorialquestion
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lea Hayes
    wrote on last edited by
    #1

    Hi all! I have created an XLS file but I am confused over a particular part of the language syntax. If I want to sort by an element attribute I can do the following (and it works):

    <xsl:sort-by select="@columnName" order="ascending" data-type="text" />

    I want to add a paramater which allows me to input which column is to be sorted by. So I tried the following:

    <xsl:param name="sortColumn" />

    <!-- Other XSL stuff goes here... -->

    <xsl:sort-by select="$sortColumn" order="ascending" data-type="text" />

    But this did not work, so I tried the following which also did not work:

    <xsl:param name="sortColumn" />

    <!-- Other XSL stuff goes here... -->

    <xsl:sort-by select="@$sortColumn" order="ascending" data-type="text" />

    Could someone please advise me on how to do this? To offer some clarity the input XML documents are structured as follows:

    <root>
    <entry columnA="value1" columnB="value2" columnC="value3" />
    <entry columnA="value4" columnB="value5" columnC="value6" />
    <entry columnA="value7" columnB="value8" columnC="value9" />
    </root>

    Many thanks! Lea Hayes

    modified on Sunday, August 3, 2008 9:30 PM

    L 1 Reply Last reply
    0
    • L Lea Hayes

      Hi all! I have created an XLS file but I am confused over a particular part of the language syntax. If I want to sort by an element attribute I can do the following (and it works):

      <xsl:sort-by select="@columnName" order="ascending" data-type="text" />

      I want to add a paramater which allows me to input which column is to be sorted by. So I tried the following:

      <xsl:param name="sortColumn" />

      <!-- Other XSL stuff goes here... -->

      <xsl:sort-by select="$sortColumn" order="ascending" data-type="text" />

      But this did not work, so I tried the following which also did not work:

      <xsl:param name="sortColumn" />

      <!-- Other XSL stuff goes here... -->

      <xsl:sort-by select="@$sortColumn" order="ascending" data-type="text" />

      Could someone please advise me on how to do this? To offer some clarity the input XML documents are structured as follows:

      <root>
      <entry columnA="value1" columnB="value2" columnC="value3" />
      <entry columnA="value4" columnB="value5" columnC="value6" />
      <entry columnA="value7" columnB="value8" columnC="value9" />
      </root>

      Many thanks! Lea Hayes

      modified on Sunday, August 3, 2008 9:30 PM

      L Offline
      L Offline
      Lea Hayes
      wrote on last edited by
      #2

      Hi all, I have finally worked out how to achieve what I need. For those interested the syntax to get the value of an attribute by paramater is:

      @*[name() = $sortBy]

      where $sortBy is the name of the paramater. Hope this is of use to someone! Lea Hayes

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups