Increment Variable count in for-each in XSLT 1.0 - xslt

I want to Increment variable in for-each loop. Here is my code.
<xsl:variable name="i" select="1" />
<xsl:variable name="oddEven" select="1" />
<xsl:for-each select="//ProfileBR">
<xsl:variable name="j" select="$i + 1" />
sharad j :: <xsl:value-of select="$j"></xsl:value-of>
<xsl:variable name="iBR" select="substring(//BRValue,$i,1)" />
<xsl:variable name="jBR" select="substring(//BRValue,$j,1)" />
<xsl:if test="$iBR='1' or $jBR='1'">
<xsl:choose>
<xsl:when test="$oddEven='1'">
<tr class="sbListOddCell">
<xsl:call-template name="JobInfoSection">
<xsl:with-param name="ii" select="$i"/>
<xsl:with-param name="jj" select="$j"/>
<xsl:with-param name="iiBR" select="$iBR"/>
<xsl:with-param name="jjBR" select="$jBR"/>
</xsl:call-template>
</tr>
<xsl:variable name="oddEven" select="0" />
</xsl:when>
<xsl:otherwise>
<tr class="sbListEvenCell">
<xsl:call-template name="JobInfoSection">
<xsl:with-param name="ii" select="$i"/>
<xsl:with-param name="jj" select="$j"/>
<xsl:with-param name="iiBR" select="$iBR"/>
<xsl:with-param name="jjBR" select="$jBR"/>
</xsl:call-template>
</tr>
<xsl:variable name="oddEven" select="1" />
</xsl:otherwise>
</xsl:choose>
</xsl:if>
<xsl:variable name="i" select="$j + 1" />
</xsl:for-each>
I want to increment i and j in every iteration but it ends up with 3 and 2 respectively after each iteration.
How can I increment i and j.
Thanks,
Sharad

Use position() to get the count of the iteration inside the for-each like this:
<xsl:variable name="j" select="$i + position()" />

Related

Attaching parent attributes to child nodes with multiple children

this is linked from Attaching ancestor attributes to child nodes
I'm extracting names from a large xml dataset, I need to extract displayname, and the other name types (currently I am only picking out Synonyms and SystematicNames). Right now with the help of an awesome person I've gotten so far, but it only extracts the first of each type...
Sample XML
<Chemical id="0000103902" displayFormula="C8-H9-N-O2" displayName="Acetaminophen [USP:JAN]">
<NameList>
<DescriptorName>Acetaminophen<SourceList><Source>MeSH</Source></SourceList></DescriptorName>
<NameOfSubstance>Acetaminophen<SourceList><Source>HSDB</Source><Source>MeSH</Source></SourceList></NameOfSubstance>
<NameOfSubstance>Acetaminophen [USP:JAN]<SourceList><Source>NLM</Source></SourceList></NameOfSubstance>
<MixtureName>Actifed Plus<SourceList><Source>MeSH</Source></SourceList></MixtureName>
<MixtureName>Jin Gang<SourceList><Source>NLM</Source></SourceList></MixtureName>
<MixtureName>Talacen<SourceList><Source>NLM</Source></SourceList></MixtureName>
<SystematicName>Acetamide, N-(4-hydroxyphenyl)-<SourceList><Source>EPA SRS</Source><Source>MeSH</Source><Source>TSCAINV</Source></SourceList></SystematicName>
<SystematicName>Acetaminophen<SourceList><Source>CCRIS</Source></SourceList></SystematicName>
<SystematicName>Acetanilide, 4'-hydroxy-<SourceList><Source>RTECS</Source></SourceList></SystematicName>
<SystematicName>Paracetamol<SourceList><Source>ECHA</Source><Source>EINECS</Source></SourceList></SystematicName>
<Synonyms>4-13-00-01091 (Beilstein Handbook Reference)<SourceList><Source>RTECS</Source></SourceList></Synonyms>
<Synonyms>Abensanil<SourceList><Source>HSDB</Source><Source>RTECS</Source></SourceList></Synonyms>
<Synonyms>Acetagesic<SourceList><Source>HSDB</Source><Source>RTECS</Source></SourceList></Synonyms>
<Synonyms>Acetamide, N-(p-hydroxyphenyl)-<SourceList><Source>RTECS</Source></SourceList></Synonyms>
</NameList>
</Chemical>
Current code
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" />
<xsl:variable name="FS">
<!-- Field seperator -->
<xsl:text>;</xsl:text>
</xsl:variable>
<xsl:variable name="LT">
<!-- Line terminator -->
<xsl:text>
</xsl:text>
</xsl:variable>
<xsl:strip-space elements="*" />
<xsl:template match="/">
<xsl:for-each select="//Chemical[#displayName != '' and #displayName != 'INDEX NAME NOT YET ASSIGNED']">
<xsl:call-template name="printValues">
<xsl:with-param name="val1" select="#id" />
<xsl:with-param name="val2" select="#displayName" />
</xsl:call-template>
<xsl:if test="normalize-space(NameList/SystematicName/text()) != ''">
<xsl:call-template name="printValues">
<xsl:with-param name="val1" select="#id" />
<xsl:with-param name="val2" select="normalize-space(NameList/SystematicName/text())" />
</xsl:call-template>
</xsl:if>
<xsl:if test="normalize-space(NameList/Synonyms/text()) != ''">
<xsl:call-template name="printValues">
<xsl:with-param name="val1" select="#id" />
<xsl:with-param name="val2" select="normalize-space(NameList/Synonyms/text())" />
</xsl:call-template>
</xsl:if>
</xsl:for-each>
</xsl:template>
<xsl:template name="printValues">
<xsl:param name="val1" />
<xsl:param name="val2" />
<!-- constants -->
<xsl:variable name="url" select="'https://chem.nlm.nih.gov/chemidplus/sid/startswith/'" />
<xsl:variable name="src" select="'nlm'" />
<xsl:text>"</xsl:text>
<xsl:call-template name="escapeQuote">
<xsl:with-param name="paramStr" select="$val2" />
</xsl:call-template>
<xsl:text>"</xsl:text>
<xsl:text>,</xsl:text>
<xsl:text>"</xsl:text>
<xsl:value-of select="concat($url, $val1)" />
<xsl:text>"</xsl:text>
<xsl:text>,</xsl:text>
<xsl:text>"</xsl:text>
<xsl:value-of select="$src" />
<xsl:text>"</xsl:text>
<xsl:text>
</xsl:text>
</xsl:template>
<xsl:template name="escapeQuote">
<xsl:param name="paramStr" />
<xsl:if test="string-length($paramStr) > 0">
<xsl:value-of select="substring-before(concat($paramStr, '"'), '"')" />
<xsl:if test="contains($paramStr, '"')">
<xsl:text>\"</xsl:text>
<xsl:call-template name="escapeQuote">
<xsl:with-param name="paramStr" select="substring-after($paramStr, '"')" />
</xsl:call-template>
</xsl:if>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
However this only gives:-
"Acetaminophen [USP:JAN]","https://chem.nlm.nih.gov/chemidplus/sid/startswith/0000103902","nlm"
"Acetamide, N-(4-hydroxyphenyl)-","https://chem.nlm.nih.gov/chemidplus/sid/startswith/0000103902","nlm"
"4-13-00-01091 (Beilstein Handbook Reference)","https://chem.nlm.nih.gov/chemidplus/sid/startswith/0000103902","nlm"
How do I go about extracting all the children in the same manner?
Printing of the text values in the <SystematicName> and <Synonyms> nodes can be achieved by adding <xsl:for-each> loop for those elements. The <xsl:if> condition can also be handled in the <xsl:for-each> selection.
Please modify the <xsl:template match="/"> as shown below.
<xsl:template match="Chemical[#displayName != '' and #displayName != 'INDEX NAME NOT YET ASSIGNED']">
<xsl:variable name="idValue" select="#id" />
<xsl:call-template name="printValues">
<xsl:with-param name="val1" select="$idValue" />
<xsl:with-param name="val2" select="#displayName" />
</xsl:call-template>
<xsl:for-each select="NameList/SystematicName[text() != '']">
<xsl:call-template name="printValues">
<xsl:with-param name="val1" select="$idValue" />
<xsl:with-param name="val2" select="normalize-space(text())" />
</xsl:call-template>
</xsl:for-each>
<xsl:for-each select="NameList/Synonyms[text() != '']">
<xsl:call-template name="printValues">
<xsl:with-param name="val1" select="$idValue" />
<xsl:with-param name="val2" select="normalize-space(text())" />
</xsl:call-template>
</xsl:for-each>
</xsl:template>
Output
"Acetaminophen [USP:JAN]","https://chem.nlm.nih.gov/chemidplus/sid/startswith/0000103902","nlm"
"Acetamide, N-(4-hydroxyphenyl)-","https://chem.nlm.nih.gov/chemidplus/sid/startswith/0000103902","nlm"
"Acetaminophen","https://chem.nlm.nih.gov/chemidplus/sid/startswith/0000103902","nlm"
"Acetanilide, 4'-hydroxy-","https://chem.nlm.nih.gov/chemidplus/sid/startswith/0000103902","nlm"
"Paracetamol","https://chem.nlm.nih.gov/chemidplus/sid/startswith/0000103902","nlm"
"4-13-00-01091 (Beilstein Handbook Reference)","https://chem.nlm.nih.gov/chemidplus/sid/startswith/0000103902","nlm"
"Abensanil","https://chem.nlm.nih.gov/chemidplus/sid/startswith/0000103902","nlm"
"Acetagesic","https://chem.nlm.nih.gov/chemidplus/sid/startswith/0000103902","nlm"
"Acetamide, N-(p-hydroxyphenyl)-","https://chem.nlm.nih.gov/chemidplus/sid/startswith/0000103902","nlm"

Display alternate style class in XSLT

I want to display alternate style class in XSLT.
Here is my code:
<xsl:variable name="oddEven" select="1" />
<xsl:for-each select="//ProfileBR">
<xsl:variable name="i" select="((position() - 1) * 2) + 1" />
<xsl:variable name="iBR" select="substring(//BRValue,$i,1)" />
<xsl:variable name="jBR" select="substring(//BRValue,$i+1,1)" />
<xsl:if test="$iBR='1' or $jBR='1'">
<xsl:choose>
<xsl:when test="$oddEven='1'">
<tr class="sbListOddCell">
<xsl:if test="$iBR=0">
<td></td>
</xsl:if>
<xsl:call-template name="JobInfoSection">
<xsl:with-param name="ii" select="$i"/>
<xsl:with-param name="jj" select="$i+1"/>
<xsl:with-param name="iiBR" select="$iBR"/>
<xsl:with-param name="jjBR" select="$jBR"/>
</xsl:call-template>
<xsl:if test="$jBR=0">
<td></td>
</xsl:if>
</tr>
<xsl:variable name="oddEven" select="0" />
</xsl:when>
<xsl:otherwise>
<tr class="sbListEvenCell">
<xsl:if test="$iBR=0">
<td></td>
</xsl:if>
<xsl:call-template name="JobInfoSection">
<xsl:with-param name="ii" select="$i"/>
<xsl:with-param name="jj" select="$i+1"/>
<xsl:with-param name="iiBR" select="$iBR"/>
<xsl:with-param name="jjBR" select="$jBR"/>
</xsl:call-template>
<xsl:if test="$jBR=0">
<td></td>
</xsl:if>
</tr>
<xsl:variable name="oddEven" select="1" />
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:for-each>
Currently the oddEven logic is not working as the value does not persist.
Note: The position is not at all related with the display. If the condition satisfy than only display the <tr> else not.
I think using the CSS will be better for this case or may be Javascript ..
table tr:nth-child(odd) td{
}
table tr:nth-child(even) td{
}
I think you can also use a counter if you have changed the loop style to be a recursive like this
<xsl:template name="loop">
<xsl:param name="other param"/>
<xsl:param name="count"/>
<!-- logic then recurse and pass the counter with $counter + 1-->
</xsl:template>
As you can each time path the param with a new value.
I hope this could help!

Increase the value of a variable being passed to call-template

I have the following bit of xsl inside a template:
<xsl:variable name="current_x" select="position_x" />
<xsl:variable name="current_y" select="position_y" />
<xsl:if test="units_display='true'">
<xsl:call-template name="DisplayBox">
<xsl:with-param name="value"><xsl:value-of select="units" /></xsl:with-param>
<xsl:with-param name="text" select="'Units'" />
</xsl:call-template>
</xsl:if>
<xsl:if test="sensor_display='true'">
<xsl:call-template name="DisplayBox">
<xsl:with-param name="value"><xsl:value-of select="sensor" /></xsl:with-param>
<xsl:with-param name="text" select="'Type'" />
</xsl:call-template>
</xsl:if>
My call-template is like this:
<xsl:template name="DisplayBox">
<xsl:param name="current_x" select="0"/>
<xsl:param name="current_y" select="0"/>
<xsl:param name="value" />
<xsl:param name="text" />
<g transform="translate({$current_x},{$current_y})">
<rect x="20" y="150" width="220" height="20" fill="#FFFFFF" stroke="black" stroke-width="1" />
<text x="25" y="168" font-family="arial" font-size="20px" fill="black">
<xsl:value-of select="$value"/>
</text>
<line x1="90" y1="150" x2="90" y2="170" stroke="black" stroke-width="1" />
<text x="95" y="168" font-family="arial" font-size="20px" fill="black">
<xsl:value-of select="$text" />
</text>
</g>
</xsl:template>
This displays the value of 'value' and 'text' inside a rectangle. The thing I cannot work out how to do, however, is to not have them write on top of each other. I want to increase the current_y value if the test="xxxx_display=true. But I am at a loss of how to achieve this.
I can't work out how I can increase the value of current_y outside of the call-template.
EDIT:
There seems to be a problem in using transform translate in the call-template. It seems to ignore those values.
I have modded the code to now be:
<xsl:if test="units_display='true'">
<g transform="translate({position_x},{position_y})">
<xsl:call-template name="DisplayBox">
<xsl:with-param name="value">
<xsl:value-of select="units" />
</xsl:with-param>
<xsl:with-param name="text" select="'Units'" />
</xsl:call-template>
</g>
</xsl:if>
<xsl:if test="sensor_display='true'">
<g transform="translate({position_x},{position_y + 20})">
<xsl:call-template name="DisplayBox">
<xsl:with-param name="value">
<xsl:value-of select="sensor" />
</xsl:with-param>
<xsl:with-param name="text" select="'Type'" />
</xsl:call-template>
</g>
</xsl:if>
But, I don't want to hard-code 'position_y + 20'. I would like the 2nd value to be at position_y if the first value display was not true, but the 2nd value to be at position_y + 20 if the first value display was true. This must be possible somehow I would hope.
By the way, don't do this:
<xsl:with-param name="value"><xsl:value-of select="sensor" /></xsl:with-param>
when you mean this:
<xsl:with-param name="value" select="sensor" />
It's not only verbose, it's also incredibly inefficient: instead of simply passing a reference to a value, you are constructing a temporary tree containing a text node that holds a copy of the value. Creating new trees is an expensive operation.
Simply pass the the parameters current_x and current_y with the adjusted values like this:
<xsl:if test="units_display='true'">
<xsl:call-template name="DisplayBox">
<xsl:with-param name="value"><xsl:value-of select="units" /></xsl:with-param>
<xsl:with-param name="text" select="'Units'" />
<xsl:with-param name="current_x" select="position_x"/>
<xsl:with-param name="current_y" select="position_y + 100"/>
</xsl:call-template>
</xsl:if>
<xsl:if test="sensor_display='true'">
<xsl:call-template name="DisplayBox">
<xsl:with-param name="value"><xsl:value-of select="sensor" /></xsl:with-param>
<xsl:with-param name="text" select="'Type'" />
<xsl:with-param name="current_x" select="position_x"/>
<xsl:with-param name="current_y" select="position_y + 200"/>
</xsl:call-template>
</xsl:if>
EDIT: If you want to go with the second approach, try to change the sensor_display part to:
<xsl:if test="sensor_display='true'">
<xsl:variable name="offset">
<xsl:choose>
<xsl:when test="units_display='true'">20</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<g transform="translate({position_x},{position_y + $offset})">
<xsl:call-template name="DisplayBox">
<xsl:with-param name="value">
<xsl:value-of select="sensor" />
</xsl:with-param>
<xsl:with-param name="text" select="'Type'" />
</xsl:call-template>
</g>
</xsl:if>
BTW, if you rephrase your question like this, it's better to start a new question.

How to write a CSV-parser using XSLT 1.0?

I need to make a CSV-parser using XSLT 1.0. I have tried a recursive approach, but I can't seem to match the line endrings, so the input to the printLine-template is always empty.
<xsl:template match="/">
<xsl:call-template name="printLine">
<xsl:with-param name="line">
<xsl:value-of select="substring-before(//csvText, '\n')"/>
</xsl:with-param>
<xsl:with-param name="remaining">
<xsl:value-of select="substring-after(//csvText, '\n')"/>
</xsl:with-param>
</xsl:call-template>
</xsl:template>
<xsl:template name="printLine">
<xsl:param name="line"/>
<xsl:param name="remaining"/>
<xsl:value-of select="$line"/><br />
<xsl:if test="remaining != ''">
<xsl:call-template name="printLine">
<xsl:with-param name="line">
<xsl:value-of select="substring-before($remaining, '\n')"/>
</xsl:with-param>
<xsl:with-param name="remaining">
<xsl:value-of select="substring-after($remaining, '\n')"/>
</xsl:with-param>
</xsl:call-template>
</xsl:if>
</xsl:template>
I found a solution to this:
<xsl:variable name="ls"><xsl:text>
</xsl:text></xsl:variable>
<xsl:variable name="fs"><xsl:text> </xsl:text></xsl:variable>
<xsl:template match="/">
<xsl:call-template name="printLine">
<xsl:with-param name="line" select="substring-before(//csvText, $ls)"/>
<xsl:with-param name="remaining" select="substring-after(//csvText, $ls)"/>
</xsl:call-template>
</xsl:template>
<xsl:template name="printLine">
<xsl:param name="line"/>
<xsl:param name="remaining"/>
<xsl:call-template name="printFields">
<xsl:with-param name="line" select="$line"/>
</xsl:call-template>
<xsl:if test="$remaining != ''">
<xsl:call-template name="printLine">
<xsl:with-param name="line" select="substring-before($remaining, $ls)"/>
<xsl:with-param name="remaining" select="substring-after($remaining, $ls)"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
<xsl:template name="printFields">
<xsl:param name="line"/>
<!-- render each line and access each field using the getFieldByIndex-template. Example: -->
<div>
<h3>
<xsl:call-template name="getFieldByIndex">
<xsl:with-param name="index" select="1"/>
<xsl:with-param name="line" select="$line"/>
</xsl:call-template>
</h3>
<p>
<xsl:call-template name="getFieldByIndex">
<xsl:with-param name="index" select="4"/>
<xsl:with-param name="line" select="$line"/>
</xsl:call-template>
</p>
</div>
</xsl:template>
<xsl:template name="getFieldByIndex">
<xsl:param name="index"/>
<xsl:param name="line"/>
<xsl:choose>
<xsl:when test="$index > 0">
<xsl:call-template name="getFieldByIndex">
<xsl:with-param name="index" select="$index -1"/>
<xsl:with-param name="line" select="substring-after($line, $fs)"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="substring-before($line,$fs)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
The line- and field separators are stored in the ls and fs variables. This example traverses a tab-serparated file. The printFields-template has to be customized for each use.

Umbraco Navigation using XSLT macro - issue with childless nodes

I have implemented the superfish navigation menu into an umbraco installation. Superfish simply takes a UL element and turns it into a hierarchical menu that shows child items when you hover over the parent (you remember when they were cool back in 1999 right?).
I cannot figure out why, on certain pages (usually ones without children), the menu does not show child items for any page. My exposure to XSLT is minimal, so i must be overlooking some logic.
You can see the actual site here Hover over 'personal training' to see the menu work, now click on 'weight management' and hey-presto the magic stops happening.
The XSLT that creates the UL structure is below, and the HTML page source tells me that its simply not generating any LI elements for child pages when the issue occurs.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxml="urn:schemas-microsoft-com:xslt"
xmlns:umbraco.library="urn:umbraco.library"
exclude-result-prefixes="msxml umbraco.library">
<xsl:output method="html" omit-xml-declaration="yes"/>
<xsl:param name="currentPage" />
<!--This sets the level that the nav starts at and tells us if we should recurse through child elements-->
<xsl:variable name="startDepth" select="/macro/startingLevel" />
<xsl:variable name="recurse" select="/macro/recurse" />
<xsl:variable name="selectBranches" select="/macro/selectBranches"></xsl:variable>
<xsl:variable name="maxMenuDepth" select="/macro/maxMenuDepth"></xsl:variable>
<xsl:variable name="forceNode" select="/macro/forceNode"></xsl:variable>
<xsl:variable name="walkChildren" select="/macro/expandChildren"></xsl:variable>
<xsl:variable name="forceHome" select="/macro/forceHome"></xsl:variable>
<xsl:variable name="securityTrimming" select="/macro/securityTrimming"></xsl:variable>
<!--Alternate page title variable in here-->
<!--Styles for the navigation-->
<xsl:variable name="ulBaseClass" select="/macro/ulBaseClass"></xsl:variable>
<xsl:variable name="branchClass" select="/macro/branchClass"></xsl:variable>
<xsl:variable name="selectedClass" select="/macro/selectedClass"></xsl:variable>
<xsl:variable name="startLevel">
<xsl:choose>
<xsl:when test="$startDepth >= 0">
<xsl:value-of select="$startDepth"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$currentPage/#level"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!--This calls first iteration of the navigation, sending the first node at the correct depth found in the ancestors of the current page-->
<xsl:template match="/">
<xsl:choose>
<xsl:when test="$forceNode">
<xsl:variable name="currentNode" select="umbraco.library:GetXmlNodeById($forceNode)"></xsl:variable>
<xsl:call-template name="nodeIterator">
<xsl:with-param name="parentNode" select="$currentNode/ancestor-or-self::*[#isDoc][#level=$startLevel]
[
string(umbracoNaviHide) != '1'
and ($securityTrimming != '1'
or umbraco.library:IsProtected(#id, #path) = false()
or umbraco.library:HasAccess(#id, #path) = true())
]" />
<xsl:with-param name="pseudoCurrentPage" select="$currentNode" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="currentNode" select="$currentPage"></xsl:variable>
<xsl:call-template name="nodeIterator">
<xsl:with-param name="parentNode" select="$currentNode/ancestor-or-self::*[#isDoc][#level=$startLevel]
[
string(umbracoNaviHide) != '1'
and ($securityTrimming != '1'
or umbraco.library:IsProtected(#id, #path) = false()
or umbraco.library:HasAccess(#id, #path) = true())
]" />
<xsl:with-param name="pseudoCurrentPage" select="$currentNode" />
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="nodeIterator">
<xsl:param name="parentNode" />
<xsl:param name="pseudoCurrentPage" />
<!-- do not show info doc node types-->
<xsl:variable name="calculatedMenuDepth" select="($parentNode/#level - $startLevel)+1" />
<xsl:if test="$parentNode/*[#isDoc] or ($calculatedMenuDepth = 1 and $forceHome)">
<ul>
<xsl:attribute name="class">
<xsl:choose>
<xsl:when test="$calculatedMenuDepth = 1">
<xsl:value-of select="$ulBaseClass" />
</xsl:when>
<!--<xsl:when test="$calculatedMenuDepth = 1">
<xsl:value-of select="concat($ulBaseClass, ' lv', $calculatedMenuDepth)" />
</xsl:when>
<xsl:when test="$calculatedMenuDepth > 1">
<xsl:value-of select="concat('lv', $calculatedMenuDepth)" />
</xsl:when>-->
</xsl:choose>
</xsl:attribute>
<xsl:if test="$forceHome = 1 and $calculatedMenuDepth = 1">
<!-- Create the class for the li element-->
<li>
<xsl:variable name="isHomeSelected">
<xsl:choose>
<xsl:when test="$currentPage/ancestor-or-self::*[#isDoc][#level=1]/#id = $currentPage/#id">1</xsl:when>
</xsl:choose>
</xsl:variable>
<xsl:call-template name="cssClassConstructor">
<xsl:with-param name="isSelected" select="$isHomeSelected" />
<xsl:with-param name="isSelectedBranch" select="0" />
<xsl:with-param name="hasChildren" select="1" />
<xsl:with-param name="selectedClass" select="$selectedClass" />
<xsl:with-param name="branchClass" select="$branchClass" />
</xsl:call-template>
<a href="{umbraco.library:NiceUrl($currentPage/ancestor-or-self::*[#isDoc][#level=1]/#id)}">
<xsl:call-template name="cssClassConstructor">
<xsl:with-param name="isSelected" select="$isHomeSelected" />
<xsl:with-param name="isSelectedBranch" select="0" />
<xsl:with-param name="hasChildren" select="0" />
<xsl:with-param name="selectedClass" select="$selectedClass" />
<xsl:with-param name="branchClass" select="$branchClass" />
</xsl:call-template>
<!--set the innerText for the a element-->
<xsl:value-of select="$currentPage/ancestor-or-self::*[#isDoc][#level=1]/text()"/>
<xsl:if test="string($currentPage/ancestor-or-self::*[#isDoc][#level=1]/text()) = ''">
<xsl:value-of select="$currentPage/ancestor-or-self::*[#isDoc][#level=1]/#nodeName"/>
</xsl:if>
</a>
</li>
</xsl:if>
<!--End force home-->
<!--for each node in the parent node that is not hidden by Umbraco-->
<xsl:for-each select="$parentNode/*[#isDoc][
string(umbracoNaviHide) != '1'
and ($securityTrimming != '1'
or umbraco.library:IsProtected(#id, #path) = false()
or umbraco.library:HasAccess(#id, #path) = true())
]">
<!--Set the current node id i.e. the node we have looped to not the current page-->
<xsl:variable name="currentNodeID" select="#id" />
<!--Is the node a branch? i.e. are there children and is it in the colletion of ancestor nodes -->
<xsl:variable name="isBranch">
<xsl:choose>
<xsl:when test="$currentPage/ancestor-or-self::*[#isDoc][#id = $currentNodeID]/child::*[#isDoc]">1</xsl:when>
</xsl:choose>
</xsl:variable>
<!--Is the node selected? i.e. is it the same as the currentPage node-->
<xsl:variable name="isSelected">
<xsl:choose>
<xsl:when test="$currentPage/#id = $currentNodeID">1</xsl:when>
<!-- parent selected -->
<xsl:when test="$pseudoCurrentPage/#id = $currentNodeID">1</xsl:when>
</xsl:choose>
</xsl:variable>
<xsl:variable name="isSelectedBranch">
<xsl:choose>
<xsl:when test="$isBranch = 1 and $selectBranches = 1">1</xsl:when>
</xsl:choose>
</xsl:variable>
<xsl:variable name="hasChildren">
<xsl:choose>
<xsl:when test="./*[#isDoc]">1</xsl:when>
</xsl:choose>
</xsl:variable>
<li>
<!-- Create the class attribute for the element-->
<xsl:call-template name="cssClassConstructor">
<xsl:with-param name="isSelected" select="$isSelected" />
<xsl:with-param name="isSelectedBranch" select="$isSelectedBranch" />
<xsl:with-param name="hasChildren" select="$hasChildren" />
<xsl:with-param name="selectedClass" select="$selectedClass" />
<xsl:with-param name="branchClass" select="$branchClass" />
</xsl:call-template>
<a href="{umbraco.library:NiceUrl(#id)}">
<xsl:call-template name="cssClassConstructor">
<xsl:with-param name="isSelected" select="$isSelected" />
<xsl:with-param name="isSelectedBranch" select="$isSelectedBranch" />
<xsl:with-param name="hasChildren" select="0" />
<xsl:with-param name="selectedClass" select="$selectedClass" />
<xsl:with-param name="branchClass" select="$branchClass" />
</xsl:call-template>
<!--set the innerText for the a element-->
<xsl:value-of select="./pageTitle/text()"/>
<xsl:if test="string(./pageTitle/text()) = ''">
<xsl:value-of select="#nodeName"/>
</xsl:if>
</a>
<!-- if it's a branch recurse through it's children-->
<xsl:if test="((($isBranch = 1 and $recurse = 1) or ($walkChildren = 1 and $pseudoCurrentPage/descendant-or-self::*[#isDoc][#id = $currentNodeID]/child::*[#isDoc])) and $maxMenuDepth > $calculatedMenuDepth)">
<xsl:call-template name="nodeIterator">
<xsl:with-param name="parentNode" select="." />
<xsl:with-param name="pseudoCurrentPage" select="$pseudoCurrentPage" />
</xsl:call-template>
</xsl:if>
</li>
</xsl:for-each>
</ul>
</xsl:if>
</xsl:template>
<xsl:template name="cssClassConstructor">
<xsl:param name="isSelected"></xsl:param>
<xsl:param name="isSelectedBranch"></xsl:param>
<xsl:param name="hasChildren"></xsl:param>
<xsl:param name="selectedClass"></xsl:param>
<xsl:param name="branchClass"></xsl:param>
<xsl:variable name="class">
<xsl:if test="$isSelected = 1">
<xsl:value-of select="concat($selectedClass,' ')"/>
</xsl:if>
<xsl:if test="$isSelectedBranch = 1">
<xsl:value-of select="concat($branchClass,' ')"/>
</xsl:if>
<xsl:if test="$hasChildren = 1">
<xsl:value-of select="'hasChildren '"/>
</xsl:if>
</xsl:variable>
<xsl:if test="string-length($class) > 0">
<xsl:attribute name="class">
<xsl:value-of select="normalize-space($class)"/>
</xsl:attribute>
</xsl:if>
</xsl:template>
</xsl:stylesheet>​
The issue you describe above isn't replicating for me (I've checked your source code using Notepad++ and a diff viewer). I see from your code that you're using the CogWorks' Flexible Navigation package. Can you ensure you're using the latest code from here?
Many thanks,
Benjamin