tags:

views:

29

answers:

1

Hi everyone..

I have a menu with three industries and an "active" option:

<ul>
<li id="p_active"><a href="active.xml">Active</a></li>
<li id="p_education"><a href="education.xml">Education</a></li>
<li id="p_energy"><a href="energy.xml">Energy</a></li>
<li id="p_services"><a href="services.xml">Services</a>
</li>
</ul>

There are a number of companies within each industry, additionally, each of them is either "Active" or "Inactive".

Upon going to a company's page, there are BACK and NEXT buttons, which will navigate through the master list of companies, to the respective adjacent company within that industry.

(i.e. Company ABC is in the Education industry, so on their page, Back and Next will go to the other companies within the Education industry). I have accomplished this in XSLT:

<xsl:choose>
    <xsl:when test="(company[@ind='Education'])">
    <xsl:value-of select="document('invest-port.xml')/portfolio/company[name=$name]/following-sibling::company[@ind='Education'][1]/link"/>
</xsl:when>
    <xsl:when test="(company[@ind='Energy'])">
    <xsl:value-of select="document('invest-port.xml')/portfolio/company[name=$name]/following-sibling::company[@ind='Energy'][1]/link"/>
</xsl:when>
</xsl:choose>

Example company XML file:

<fragment>
    <company ind="Education" stat="Active">Company ABC</company>    
    <hq>Boston, MA</hq>
    <desc>This company makes products for schools</desc>
</fragment>

This works, with the Industry as the default sort key, based on the code I've written. My problem is this: I want to make it so when the user clicks "ACTIVE" in the menu, the Back and Next buttons will navigate through the @status="Active" attributes, INSTEAD of by Industry.

What is the best way to approach this? I've looked at a lot of different solutions, but I can't seem to figure out the best way of doing this...Thanks!

A: 

First off, I would try to get rid of the choose and try to use a variable to represent the selected industry:

company[@ind = $ind]

Then, put a choose to determine which way you're going to find the next/prev company.

<xsl:choose>
    <xsl:when test="$selectionMethod = 'Active'">
        <xsl:value-of select="document('invest-port.xml')/portfolio/company[name=$name]/following-sibling::company[@stat='Active'][1]/link"/>
    </xsl:when>
    <xsl:otherwise>
        existing code
    </xsl:otherwise>
</xsl:choose>
Seattle Leonard
Thanks for the quick response. Where are you getting $selectionMethod from? How does the code know I've accessed this through the Active link?
Andrew Parisi
Just for a bit more information, when accessing a company's file, each company page uses the same XSL stylesheet, which is where this code is currently going. So how should I go about telling that style sheet that the user wants to navigate in a different manner, depending on which link they clicked?
Andrew Parisi
You can send parameters to a style sheet. I don't know your exact implementation, but this would be a good place to put it.
Seattle Leonard
http://www.w3schools.com/XSL/el_param.asp
Seattle Leonard
Sounds like the right direction..could you possibly provide an example of parameter implementation? I've never used them...I'm surprised I've gotten this far...Thanks!
Andrew Parisi
I find parameters a tad confusing...not entirely sure how to integrate them with the user's choices..could you possibly provide a short example?
Andrew Parisi
How you send a parameter to the stylesheet is going to depend on the XSL parser that you are using. Most XSL parsers have an overloaded method for sending parameter to the stylesheet.
Seattle Leonard
Well I am just starting to mess around with Saxon..if that helps at all
Andrew Parisi
I've heard good things about Saxon, but I've only used the XSL parser that is built into .NETP.S. don't forget to give up votes for good answers :)
Seattle Leonard