Forum Moderators: open
I want the output to sort the companies first by state THEN within each state, sort the company names alphabetically:
Alabama
Company A
Company B
Arkansas
Company M
Company S
Company Y
Hawaii
Company F
Company L
Company P
And so on.
I tried
<xsl:sort select="state"/>
<xsl:sort select=companyname"/>
but what happens is it sorts by company name, not by state. If I remove <xsl:sort select=companyname"/>, it sorts perfectly by state, but the comapny names are in the order they fall in the xml. I am sure the solution is simple, but I am missing it. Any help would be appreciated.
Marshall
for-each by state
<xsl:sort select="state"/>
for-each by company
<xsl:sort select="companyname"/>
Is it possible to specify multiple selects in one sort? This may be the way to go if nested loops not appropriate.
I think what you're describing is multiple templates in the XSLT. That's the one trick I have not tried yet, but probably will when I get time.
cmarshall, OOPS! I was tired.
Anyway, what complicates the problem is that the XML also has the states listed. In <companyname>, is the name of the state and in <state> is the abbreviation, and the <state> has an option, either 1 or 2. The XSL contains two <if> statements, to the effect:
<xsl:if test="state[@option = '2']"> it makes the <companyname>, hence the state's name, a bookmark on the output.
<xsl:if test="state[@option = '1']"> it makes the <companyname> a link. I tried using a <choose> for this, but the results were the same.
I think there ought to be a <sort> tag with a "then" function, kind of like:
<xsl:sort test="state 'then' companyname"/> (or some symbol for 'then', say an 'x' or '+'. But that would make it too easy :)
I'll keep trying and let all of you know if I get it to work. Thanks for your help.
Marshall
I should add that the problem boils down to this:
If a company whose name begins with an "L" is located in Nevada (NV), then the output looks like this when I add the sort by companyname:
NEBRASKA
Company L in NV
NEVADA (NV)
Company M in NV
Company S in NV
and so on.
The problem is to get the state's name first regardless of the company names. Make sense?
[edited by: Marshall at 5:49 am (utc) on July 9, 2007]
I added a tag to the XML <statename></statename> and moved the name of the state to that tag. I deleted all text from the <companyname> tag where the state name was. In the XSL, instead of having it <xsl:value-of select="title"/> under the first <if> statement, it now has <xsl:value-of select="statename"/>. Since the <companyname> tag is blank, it will always come first.
Thanks for all your help. Hope this can help someone else.
Marshall