PDA

View Full Version : XSL sorting info correctly, but not after link is clicked


utahman3431
06-10-2008, 03:54 AM
I was finally able to get some XML data sorted correctly using an XSL document, but I am having some issues with it not staying numbered correctly for a link.
Let me explain a little further.

I have a support site I am creating that doesn't have the option of using server-side scripting. I am using an xml document to hold all of the site information (help articles, contact lists, etc). I was wanting to make it to where I can add a new help article at the bottom of the XML doc and have the XSL stylesheet sort the documents alphabetically. I have the code to where it will finally do that for the article titles:

<xsl:template match="/">
<ul id="subnav">
<xsl:for-each select="help_articles/support_doc">
<xsl:sort select="header" />
<li>
<a href="javascript://" onclick="show({position() - 1})" >
<xsl:value-of select="header" />
</a>
</li>
</xsl:for-each>
</ul>
</xsl:template>


With the above code I can get a list of all articles to display alphabetically by "header" name. When I click on the corresponding link it will display the correct information until I come to an article that isn't alphabetically placed in the correct location within the XML document:


<support_doc>
<name></name>
<header>DC Ranch</header>
<title>temp</title>
<body>temp</body>
</support_doc>

<support_doc>
<name></name>
<header>Display Language</header>
<title>temp</title>
<body>temp</body>
</support_doc>

<support_doc>
<name>bob</name>
<header>Bob is Testing</header>
<title>Bob is Testing</title>
<body>test</body>
</support_doc>
...

As soon as I click on the link for "Bob is testing" in the menu, it shows the information for the article at that actual position in the XML document.
Am I using the wrong code in the link ({postion()-1})?

utahman3431
06-21-2008, 03:20 AM
Ok, after a few days of trying different things, I finally found the solution to my problem. I changed the for-each statement and used apply-templates in its stead. I used xsl:number to show the original node position in my xml document. Here is what the new code looks like:


<xsl:template match="chs_document">

<ul id="subnav">

<xsl:apply-templates select="support_doc">
<xsl:sort select="header"/>
</xsl:apply-templates>

</ul>

</xsl:template>

<xsl:template match="support_doc">

<li>
<a>
<xsl:attribute name="href">
javascript://
</xsl:attribute>
<xsl:attribute name="onclick">
show(
<xsl:number />
)
</xsl:attribute>


<xsl:value-of select="header" /> <xsl:number />
</a>

</li>

</xsl:template>


I know no one responded to my question, but I figured I'd post this in case anyone else needed help.

I have other questions, but I'll post them in a new thread.