Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 17th, 2007, 07:37 AM
Authorized User
 
Join Date: Jan 2006
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
Default sort on specific attribute

hello

I am trying to feel according to an attribute name dbcolumn and I want to sort the response according to other attribute name order.
input file:
<entities>
<entity eid="A" tid="501" plural-tid="502" grouping-tid="503" plural-grouping-tid="504" length="256"><display mandatory="yes" order="1"></display><data class="activity" type="varchar" dbcolumn="MAIL_MSG" mandatory="yes" last-summary="all" collection-id="msg"></data></entity>
<entity eid="U" tid="511" plural-tid="512" grouping-tid="513" plural-grouping-tid="514" length="256"><display mandatory="no" order="6"></display><data class="user_name" type="varchar" dbcolumn="SENDER" mandatory="yes" last-summary="all" collection-id="sender"></data></entity>
<entity eid="C" tid="521" plural-tid="522" grouping-tid="523" plural-grouping-tid="524" length="256"><display mandatory="no" order="7"></display><data class="client_ip" type="varchar" dbcolumn="SENDER_IP" mandatory="yes" last-summary="all" collection-id="C_IP"></data></entity>
<entity eid="T" tid="531" plural-tid="532" length="256"><display mandatory="no" order="9"></display><data class="user-defined" type="varchar" dbcolumn="MSG_TYPE" mandatory="yes" last-summary="all" collection-id="type"></data></entity>
<entity eid="I" tid="541" plural-tid="542" grouping-tid="543" plural-grouping-tid="544" length="256"><display mandatory="no" order="2"></display><data class="instance" type="varchar" mandatory="yes" last-ummary="all"></data></entity></entity></entities>

xsl file that is working now
<case v2="">
<xsl:for-each select = "$id-db_columns">
<xsl:call-template name="apptier-graphs">
    <xsl:with-param name="v1" select="concat('!~isGraphEnabled.', @dbcolumn, '!~')"/>
    <xsl:with-param name="node" select="concat('/entity[@key=', $apos, 'common', $apos, ']/graphs/graph[@key=', $apos, @dbcolumn, $apos, ']')"/>
</xsl:call-template>
</xsl:for-each>
<xsl:call-template name="apptier-graphs">
    <xsl:with-param name="v1" select="concat('!~isGraphEnabled.', $instance_column_name, '!~')"/>
    <xsl:with-param name="node" select="concat('/entity[@key=', $apos, 'common', $apos, ']/graphs/graph[@key=', $apos, $instance_column_name, $apos, ']')"/>
</xsl:call-template>
<xsl:call-template name="apptier-graphs">
    <xsl:with-param name="v1" select="concat('!~isGraphEnabled.', $server_column_name, '!~')"/>
    <xsl:with-param name="node" select="concat('/entity[@key=', $apos, 'common', $apos, ']/graphs/graph[@key=', $apos, $server_column_name, $apos, ']')"/>
</xsl:call-template>
</case>

out put now:
<select v1="!~isGraphEnabled.SERVICE_ID!~">
  <case v2="true">
   <include import="this-I3-entity" node="/entity[@key='common']/graphs/graph[@key='SERVICE_ID']"/>
  </case>
</select>
<select v1="!~isGraphEnabled.HANDLER_TYPE!~">
  <case v2="true">
   <include import="this-I3-entity" node="/entity[@key='common']/graphs/graph[@key='HANDLER_TYPE']"/>
  </case>
</select>
<select v1="!~isGraphEnabled.CLASS_NAME!~">
  <case v2="true">
   <include import="this-I3-entity" node="/entity[@key='common']/graphs/graph[@key='CLASS_NAME']"/>
  </case>
</select>
<select v1="!~isGraphEnabled.COMMAND_LINE!~">
  <case v2="true">
   <include import="this-I3-entity" node="/entity[@key='common']/graphs/graph[@key='COMMAND_LINE']"/>
  </case>
</select>
<select v1="!~isGraphEnabled.SERVER_PRODUCT!~">
  <case v2="true">
   <include import="this-I3-entity" node="/entity[@key='common']/graphs/graph[@key='SERVER_PRODUCT']"/>
  </case>
</select>
<select v1="!~isGraphEnabled.EXIT_CODE!~">
  <case v2="true">
   <include import="this-I3-entity" node="/entity[@key='common']/graphs/graph[@key='EXIT_CODE']"/>
  </case>
</select>
<select v1="!~isGraphEnabled.REAL_COMMUNICATION!~">
  <case v2="true">
   <include import="this-I3-entity" node="/entity[@key='common']/graphs/graph[@key='REAL_COMMUNICATION']"/>
  </case>
</select>
<select v1="!~isGraphEnabled.CLIENT_PRODUCT!~">
  <case v2="true">
   <include import="this-I3-entity" node="/entity[@key='common']/graphs/graph[@key='CLIENT_PRODUCT']"/>
  </case>
</select>
<select v1="!~isGraphEnabled.CLIENT_HOST!~">
  <case v2="true">
   <include import="this-I3-entity" node="/entity[@key='common']/graphs/graph[@key='CLIENT_HOST']"/>
  </case>
</select>
<select v1="!~isGraphEnabled.instance!~">
  <case v2="true">
   <include import="this-I3-entity" node="/entity[@key='common']/graphs/graph[@key='instance']"/>
  </case>
</select>
<select v1="!~isGraphEnabled.SERVER!~">
  <case v2="true">
   <include import="this-I3-entity" node="/entity[@key='common']/graphs/graph[@key='SERVER']"/>
  </case>
</select>

I would like to know how will I make the output sorted by the order attribute that I have in the input file and not change the schema of the xsl file?

thanks


 
Old July 17th, 2007, 09:23 AM
Authorized User
 
Join Date: Jan 2006
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I would like to sort only the for-each. (no need to sort instance and server attributes)
I tried to run sort
<xsl:sort data-type="number" select="/etd/*/entity/display/@order"/>
but the result came out the same.


 
Old July 17th, 2007, 09:42 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

It only makes sense to sort if the sort key is different for each node. Using an expression like select="/etd/*/entity/display/@order" starts from the root of the document, there's nothing here that depends on the context node. You need a relative path expression, for example select="display/@order".

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy specific data in specific cells of sheet2 yogeshyl Excel VBA 1 May 14th, 2007 07:40 AM
Sort Table Columns by Table Header Attribute omrieliav XSLT 4 June 7th, 2006 01:05 AM
Change Sort-by attribute based on parent tclancy XSLT 2 March 24th, 2006 05:00 PM
how to sort cross tab.sort based on row total joxa83 Crystal Reports 7 March 2nd, 2006 09:12 AM
xsl:sort- select attribute, syntax question Flashlight XSLT 3 August 14th, 2003 12:27 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.