XSLT - how to output lookup table elements as a list

Hi there, I am working on an xsl file which uses templates and a lookup table working off a very simple xml file.

<?xml version="1.0" encoding="ISO-8859-1"?>

<?xml-stylesheet type="text/xsl" href="example.xsl"?>

<Alias>
	<Age>40</Age>
	<BMI>28.98</BMI>
	<HipToWaist>0.9</HipToWaist>
	<Height>1.93</Height>
	<Weight>107.96</Weight>
	<N1>1</N1>
	<N2>1</N2>
	<N3>3</N3> 
	<N4>5</N4>
	<N5>3</N5>
	<N6>1</N6>
	<N7>3</N7>
	<N8>5</N8>
	<N9>7</N9>
	<N10>4</N10>
	<N11>7</N11>
	<N12>7</N12>
	<N13>7</N13>
</Alias>

Open in new window


For each 'N' node there are 7 possible outcomes. These typically include an image, some text and links. I have managed (with a lot of help from Gertone ;) to get a working xsl file that output all data perfectly only now I am having issues due to the basic nature of the xml file in that I cannot position some elements as I would like.

Here is my xsl:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:map="#internal#"
     exclude-result-prefixes="map"
    version="1.0">
    <xsl:template match="/">
        <html>
            <body>
            	<h1 class="results-header">Your Results</h1>
            	<table>
                    <xsl:apply-templates select="Alias/*[string(number(substring-after(name(), 'N'))) = 'NaN']"/>
                </table>
                <xsl:apply-templates select="Alias/*[not(string(number(substring-after(name(), 'N'))) = 'NaN')]"/>
            </body>
        </html>
    </xsl:template>
    <xsl:template match="br">
      <xsl:copy-of select="."/>
 </xsl:template>
     <xsl:template name="htmLink">
  <xsl:param name="dest" select="UNDEFINED"/> 
  <xsl:element name="a">
    <xsl:attribute name="href">
      <xsl:value-of select="$dest"/>
    </xsl:attribute>
    <xsl:apply-templates/> 
  </xsl:element> 
</xsl:template> 
    <xsl:template match="N1">
        <tr><th><xsl:value-of select="name()"/></th><td><xsl:value-of select="."/></td></tr>
    </xsl:template>
    <xsl:template match="N1">
        <xsl:variable name="value" select="."></xsl:variable>
        <xsl:choose>
            <xsl:when test="document('')//map:N1[@value = $value]">
              <div id="wellbeing-wrapper">
                <xsl:variable name="N1" select="document('')//map:N1[@value = $value]"/>
                <div class="results-copy">
                <h2 class="wellbeing-header"><xsl:value-of select="$N1/@heading"/></h2>
                <h3 class="wellbeing-result"><xsl:value-of select="$N1/@type"/></h3>
                <p class="wellbeing-copy"><xsl:apply-templates select="$N1/node()"/></p>
                </div>
                <div class="result_img"><img src="images/results/n1/{$N1/@img}" border="0" alt="" /></div>
              </div>
            </xsl:when>
            <xsl:otherwise>
                <h3>It was not possible to calculate your score. Perhaps you forgot to fill in all question fields</h3>
            </xsl:otherwise>
        </xsl:choose>
 </xsl:template>
 <xsl:template match="N2">
  <div class="break"><img src="images/break-right.jpg" border="0" alt="" />
 </div>
 	<h3 class="wellbeing-summary">Your Wellbeing Results Summary:</h3>
    <div id="summary-slug">Lifestyle and environmental factors that have contributed to your wellbeing score</div>
    	<h4 class="summary-header">Lifestyle Behaviour</h4>
        <xsl:variable name="value" select="."></xsl:variable>
        <xsl:choose>
            <xsl:when test="document('')//map:N2[@value = $value]">
              <div class="lifestyle-wrapper">
                <xsl:variable name="N2" select="document('')//map:N2[@value = $value]"/>
                  <a href="http://www.some-url.com" class="lifestyle-header"><img src="images/results/n2/{$N2/@img}" class="img-swap" border="0" alt=""/></a>
                   <div class="copy-container">
                   <div class="lifestyle-copy"><xsl:apply-templates select="$N2/node()"/></div>
                   </div>
                </div> 
            </xsl:when>
            <xsl:otherwise>
                <h3>It was not possible to calculate your score. Perhaps you forgot to fill in all question fields</h3>
            </xsl:otherwise>
        </xsl:choose>
 </xsl:template>
 <xsl:template match="N3">
        <xsl:variable name="value" select="."></xsl:variable>
        <xsl:choose>
            <xsl:when test="document('')//map:N3[@value = $value]">
              <div class="lifestyle-wrapper">
                <xsl:variable name="N3" select="document('')//map:N3[@value = $value]"/>
                  <a href="http://www.some-url.com" class="lifestyle-header"><img src="images/results/n3/{$N3/@img}" class="img-swap" border="0" alt=""/></a>
                   <div class="copy-container">
                   <div class="lifestyle-copy"><xsl:apply-templates select="$N3/node()"/></div>
                   </div>
                </div>
            </xsl:when>
            <xsl:otherwise>
                <h3>It was not possible to calculate your score. Perhaps you forgot to fill in all question fields</h3>
            </xsl:otherwise>
        </xsl:choose>
 </xsl:template>
  <xsl:template match="N4">
        <xsl:variable name="value" select="."></xsl:variable>
        <xsl:choose>
            <xsl:when test="document('')//map:N4[@value = $value]">
              <div class="lifestyle-wrapper">
                <xsl:variable name="N4" select="document('')//map:N4[@value = $value]"/>
                  <a href="http://www.some-url.com" class="lifestyle-header"><img src="images/results/n4/{$N4/@img}" class="img-swap" border="0" alt=""/></a>
                   <div class="copy-container">
                   <div class="lifestyle-copy"><xsl:apply-templates select="$N4/node()"/></div>
                   </div>
                </div>
            </xsl:when>
            <xsl:otherwise>
                <h3>It was not possible to calculate your score. Perhaps you forgot to fill in all question fields</h3>
            </xsl:otherwise>
        </xsl:choose>
 </xsl:template>
  <xsl:template match="N5">
        <xsl:variable name="value" select="."></xsl:variable>
        <xsl:choose>
            <xsl:when test="document('')//map:N5[@value = $value]">
              <div class="lifestyle-wrapper">
                <xsl:variable name="N5" select="document('')//map:N5[@value = $value]"/>
                  <a href="http://www.some-url.com" class="lifestyle-header"><img src="images/results/n5/{$N5/@img}" class="img-swap" border="0" alt=""/></a>
                   <div class="copy-container">
                   <div class="lifestyle-copy"><xsl:apply-templates select="$N5/node()"/></div>
                   </div>
                </div>
            </xsl:when>
            <xsl:otherwise>
                <h3>It was not possible to calculate your score. Perhaps you forgot to fill in all question fields</h3>
            </xsl:otherwise>
        </xsl:choose>
 </xsl:template>
  <xsl:template match="N6">
        <xsl:variable name="value" select="."></xsl:variable>
        <xsl:choose>
            <xsl:when test="document('')//map:N6[@value = $value]">
              <div class="lifestyle-wrapper">
                <xsl:variable name="N6" select="document('')//map:N6[@value = $value]"/>
                  <a href="http://www.some-url.com" class="lifestyle-header"><img src="images/results/n6/{$N6/@img}" class="img-swap" border="0" alt=""/></a>
                   <div class="copy-container">
                   <div class="lifestyle-copy"><xsl:apply-templates select="$N6/node()"/></div>
                   </div>
                </div>
            </xsl:when>
            <xsl:otherwise>
                <h3>It was not possible to calculate your score. Perhaps you forgot to fill in all question fields</h3>
            </xsl:otherwise>
        </xsl:choose>
 </xsl:template>
    <map:lookup>
        <map:N1 value="1" heading="Your current Wellbeing Score Is:" type="Critical" img="score_01.jpg">Your results below will indicate the lifestyle behaviours and living environment that have contributed to this score. For your long term well being it is important to make changes to your lifestyle to improve both your short terms and long term wellbeing.
       <br />
       <br />
        The results below also indicate a high risk of poor quality of life in old age.
       <br />
       <br />
        You may consider using some of the suggested external support services to help.
        </map:N1> 
        <map:N1 value="2" heading="Your current Wellbeing Score Is:" type="Very Low" img="score_02.jpg">Your results below will indicate the lifestyle behaviours and living environment that have contributed to this score. For your long term well being it is important to make changes to your lifestyle to improve both your short terms and long term wellbeing.
       <br />
       <br />
        The results below also indicate a high risk of poor quality of life in old age.
       <br />
       <br />
        You may consider using some of the suggested external support services to help.
        </map:N1> 
        <map:N1 value="3" heading="Your current Wellbeing Score Is:" type="Low" img="score_03.jpg">Your results below will indicate the lifestyle behaviours and living environment that have contributed to this score. For your long term well being it is important to make changes to your lifestyle to improve both your short terms and long term wellbeing.
       <br />
       <br />       
        The results below also indicate a high risk of poor quality of life in old age.
       <br />
       <br />        
        You may consider using some of the suggested external support services to help.
        </map:N1> 
        <map:N1 value="4" heading="Your current Wellbeing Score Is:" type="Moderate" img="score_04.jpg">Your results below will indicate the lifestyle behaviours and living environment that have contributed to this score. For your long term well being it is important to make changes to your lifestyle to improve both your short terms and long term wellbeing.
       <br />
       <br />       
        The results below also indicate a high risk of poor quality of life in old age.
       <br />
       <br />        
        You may consider using some of the suggested external support services to help.
        </map:N1> 
        <map:N1 value="5" heading="Your current Wellbeing Score Is:" type="Good" img="score_05.jpg">Your results below will indicate the lifestyle behaviours that have contributed to make this score good. For your long term wellbeing it important to maintain these behaviours especially if life gets tougher.. 
</map:N1> 
        <map:N1 value="6" heading="Your current Wellbeing Score Is:" type="Very Good" img="score_06.jpg">Your results below will indicate the lifestyle behaviours that have contributed to make this score very good. For your long term wellbeing it important to maintain these behaviours especially if life gets tougher.. 
</map:N1> 
        <map:N1 value="7" heading="Your current Wellbeing Score Is:" type="Excellent" img="score_07.jpg">Your results below will indicate the lifestyle behaviours that have contributed to make this score excellent. For your long term wellbeing it important to maintain these behaviours especially if life gets tougher.. 
</map:N1> 
        
       
       
       
       
        <map:N2 value="1" heading="Exercise" img="critical_01.jpg">Your activity levels are critically low. To help improve your quality of life both now and in the long term it is important to try and increase these levels. Further help can be sought from:
        <br />
        <br />
<a href="http://www.some-url.com">Some exercise website</a>
        <br />
        <br />
        Physical activity can have a major impact on general wellbeing. Wellbeing is maintained or improved by habitual physical activity in a wide spectrum of different ways, ranging from psychological health, through general energy levels to the prevention of major degenerative diseases and slowing of ageing processes. 
		<br />
        <br />
        Did you know.
        <br />
        <br />
        Aphebe Tip: You may consider using some of the suggested external support services to help.
        </map:N2> 
        <map:N2 value="2" heading="Exercise" img="very_low_01.jpg">Your activity levels are very low. To help improve your quality of life both now and in the long term it is important to try and increase these levels. Further help can be sought from:
        <br />
        <br />
<a href="http://www.some-url.com">Some exercise website</a>
        <br />
        <br />        
        Physical activity can have a major impact on general wellbeing. Wellbeing is maintained or improved by habitual physical activity in a wide spectrum of different ways, ranging from psychological health, through general energy levels to the prevention of major degenerative diseases and slowing of ageing processes. 
        <br />
        <br />
        Did you know.
        <br />
        <br />        
        Aphebe Tip: You may consider using some of the suggested external support services to help.
        </map:N2> 
        <map:N2 value="3" heading="Exercise" img="low_01.jpg">Your activity levels are low. To help improve your quality of life both now and in the long term it is important to try and increase these levels. Further help can be sought from:
        <br />
        <br />
<a href="http://www.some-url.com">Some exercise website</a>
        <br />
        <br />        
        Physical activity can have a major impact on general wellbeing. Wellbeing is maintained or improved by habitual physical activity in a wide spectrum of different ways, ranging from psychological health, through general energy levels to the prevention of major degenerative diseases and slowing of ageing processes. 
        <br />
        <br />
        Did you know.
        <br />
        <br />       
        Aphebe Tip: You may consider using some of the suggested external support services to help.
        </map:N2> 
        <map:N2 value="4" heading="Exercise" img="moderate_01.jpg">Your activity levels are moderate. To help improve your quality of life both now and in the long term it is important to try and increase these levels. Further help can be sought from:
        <br />
        <br />
<a href="http://www.some-url.com">Some exercise website</a>
        <br />
        <br />        
        Physical activity can have a major impact on general wellbeing. Wellbeing is maintained or improved by habitual physical activity in a wide spectrum of different ways, ranging from psychological health, through general energy levels to the prevention of major degenerative diseases and slowing of ageing processes. 
        <br />
        <br />
        Did you know.
        <br />
        <br />               
        Aphebe Tip: You may consider using some of the suggested external support services to help.
        </map:N2> 
        <map:N2 value="5" heading="Exercise" img="good_01.jpg">Your activity levels are good. To help maintain your quality of life both now and in the long term it is important to try and maintain these levels. Further help can be sought from:
        <br />
        <br />
<a href="http://www.some-url.com">Some exercise website</a>
        <br />
        <br />        
        Physical activity can have a major impact on general wellbeing. Wellbeing is maintained or improved by habitual physical activity in a wide spectrum of different ways, ranging from psychological health, through general energy levels to the prevention of major degenerative diseases and slowing of ageing processes. 
        <br />
        <br />       
        Did you know.
        <br />
        <br />                
        Aphebe Tip: You may consider using some of the suggested external support services to help.</map:N2> 
        <map:N2 value="6" heading="Exercise" img="very_good_01.jpg">Your activity levels are very good. To help maintain your quality of life both now and in the long term it is important to try and maintain these levels. Further help can be sought from:
        <br />
        <br />
<a href="http://www.some-url.com">Some exercise website</a>
        <br />
        <br />        
        Physical activity can have a major impact on general wellbeing. Wellbeing is maintained or improved by habitual physical activity in a wide spectrum of different ways, ranging from psychological health, through general energy levels to the prevention of major degenerative diseases and slowing of ageing processes. 
        <br />
        <br />       
        Did you know.       
        <br />
        <br />        
        Aphebe Tip: You may consider using some of the suggested external support services to help.</map:N2> 
        <map:N2 value="7" heading="Exercise" img="excellent_01.jpg">Your activity levels are excellentt. To help maintain your quality of life both now and in the long term it is important to try and maintain these levels. Further help can be sought from:
        <br />
        <br />
<a href="http://www.some-url.com">Some exercise website</a>
        <br />
        <br />        
        Physical activity can have a major impact on general wellbeing. Wellbeing is maintained or improved by habitual physical activity in a wide spectrum of different ways, ranging from psychological health, through general energy levels to the prevention of major degenerative diseases and slowing of ageing processes. 
        <br />
        <br />       
        Did you know.
        <br />
        <br />                
        Aphebe Tip: You may consider using some of the suggested external support services to help.</map:N2> 
 </map:lookup>
    
</xsl:stylesheet>

Open in new window


(I've only included the first 2 'N' nodes of data within the lookup table here but you get the picture).

An example of how this currently transforms can be viewed here:

http://www.mularam.com/client/aphebe/results.php


What I would like to do is position the content within one div container so that the colour coded headers run down the left and the text content is stacked on top of each other so that I could implement a jQuery accordion or some other such function to slide the text content in and out.

An example of how this would look can be seen here:

http:www.mularam.com/client/aphebe/report-mock.jpg

As you can see the nodes are separated into two content blocks so any solution would have to bear this in mind i.e. nodes 'N2 - N6' in one block, node 'N7 - N12' in another.

I know that i will have to strip out the div classes from the current templates - I just cannot figure out how to separate the list images from the text content and if it's purely a CSS issue, or something that I have to address in the xsl templates.

Many thanks in advance

Any advice is much appreciated
mularamAsked:
Who is Participating?
 
Geert BormansInformation ArchitectCommented:
Here is what I think you need.

I added comments. You need to understand the mechanism of apply-templates very well.
apply-templates pushes out a selection of nodes
all nodes are evaluated by all templates and the closest match wins
the more specific a template match is, the higher its precedence
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">
    <xsl:strip-space elements="*"/>
    <xsl:output indent="yes"/>
    <xsl:key name="node" match="node" use="@GroupID"/>
    <!-- standaard template catches all in default mode -->
    <xsl:template match="*">
        <xsl:copy>
            <xsl:copy-of select="@*"/>
            <xsl:apply-templates select="node()"/> 
            <!-- create groups when current context is the navigation element -->
            <!-- use muenchian for that -->
            <xsl:if test="self::navigation">
                <xsl:for-each select="node/node[generate-id() = generate-id(key('node', @GroupID)[1])]">
                    <xsl:variable name="this-group-id" select="@GroupID"/>
                    <node GroupTitle="{@GroupTitle}" GroupCode="{@GroupCode}" GroupID="{//@GroupID}">
                        <nodes>
                            <!-- push out all the nodes that have this particular group ID -->
                            <xsl:apply-templates select="ancestor::navigation/node/node[@GroupID = $this-group-id]" mode="group"></xsl:apply-templates>
                        </nodes>
                    </node>
                </xsl:for-each>
            </xsl:if>
        </xsl:copy>
    </xsl:template>
    
    <!-- in default mode this specific match takes precedence over the more general match="*" -->
    <!-- this template deletes all node that have a group id and no children that don't have a group id -->
    <xsl:template match="*[normalize-space(@GroupCode) and not(*[not(normalize-space(@GroupCode))])]"/>
    
    <!-- in mode group: copy all node that have a group id -->
    <xsl:template match="node[normalize-space(@GroupCode)]" mode="group">
        <xsl:copy>
            <xsl:apply-templates select="@*" mode="group"/>
            <xsl:apply-templates select="node()" mode="group"/>
        </xsl:copy>            
    </xsl:template>
    
    <!-- in mode group, just process the content of the node elements -->
    <!-- since we have a more specific match with @GroupId, this means only the node that don't have a group id -->
    <xsl:template match="node" mode="group">
        <xsl:apply-templates select="node()" mode="group"/>
    </xsl:template>
    
    <!-- group mode: remove all other elements (not specified in higher up templates) -->
    <xsl:template match="*" mode="group"/>
    
    <!-- in mode group, copy all attributes (except those that have a more specif template match with other instructions -->
    <xsl:template  match="@*" mode="group">
        <xsl:attribute name="{name()}">
            <xsl:value-of select="."/>
        </xsl:attribute>
    </xsl:template>
    <!-- node attributes to be deleted have an empty template each -->
    <xsl:template match="@GroupTitle" mode="group"/>
    <xsl:template match="@GroupCode" mode="group"/>
    <xsl:template match="@GroupID" mode="group"/>
</xsl:stylesheet>

Open in new window

0
 
Geert BormansInformation ArchitectCommented:
I think this way you can group them (I did not fill in class attributes and titles
<xsl:template match="/">
        <html>
            <body>
                <h1 class="results-header">Your Results</h1>
                <table>
                    <xsl:apply-templates select="Alias/*[string(number(substring-after(name(), 'N'))) = 'NaN']"/>
                </table>
                <div>
                    <xsl:apply-templates select="Alias/N1"/>
                </div>
                <div>
                    <xsl:apply-templates select="Alias/N2 | Alias/N3 | Alias/N4 | Alias/N5 | Alias/N6 "/>
                </div>
                <div>
                    <xsl:apply-templates select="Alias/N7 | Alias/N8 | Alias/N9 | Alias/N10 | Alias/N11  | Alias/N12 "/>
                </div>
            </body>
        </html>
    </xsl:template>

Open in new window

0
 
Geert BormansInformation ArchitectCommented:
I have changed your br template, so it removes the namespace nodes

    <xsl:template match="br">
        <xsl:element name="br"/>
    </xsl:template>

And you should remove th efirst template for N1 since the duplicat makes it ambiguous
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
mularamAuthor Commented:
Hi Gertone

Which template are you referring to? I've removed

<xsl:template match="N1">
        <tr><th><xsl:value-of select="name()"/></th><td><xsl:value-of select="."/></td></tr>
    </xsl:template>

So N1 displays only once but the other nodes are duplicating - I think I may have mis-read your suggestion above. Here is my code

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:map="#internal#"
     exclude-result-prefixes="map"
    version="1.0">
    <xsl:template match="/">
        <html>
            <body>
            	<h1 class="results-header">Your Results</h1>
            	<table>
                    <xsl:apply-templates select="Alias/*[string(number(substring-after(name(), 'N'))) = 'NaN']"/>
                </table>
                <xsl:apply-templates select="Alias/*[not(string(number(substring-after(name(), 'N'))) = 'NaN')]"/>
                <div>
                    <xsl:apply-templates select="Alias/N1"/>
                </div>
                <div class="break"><img src="images/break-right.jpg" border="0" alt="" />
 				</div>
 				<h3 class="wellbeing-summary">Your Wellbeing Results Summary:</h3>
    			<div id="summary-slug">Lifestyle and environmental factors that have contributed to your wellbeing score</div>
    			<h4 class="summary-header">Lifestyle Behaviour</h4>
                <div id="basic-accordian" class="lifestyle-wrapper">
                <xsl:apply-templates select="Alias/N2 | Alias/N3 | Alias/N4 | Alias/N5 | Alias/N6 "/>
                </div>
            </body>
        </html>
    </xsl:template>
    <xsl:template match="br">
        <xsl:element name="br"/>
    </xsl:template>
     <xsl:template name="htmLink">
  <xsl:param name="dest" select="UNDEFINED"/> 
  <xsl:element name="a">
    <xsl:attribute name="href">
      <xsl:value-of select="$dest"/>
    </xsl:attribute>
    <xsl:apply-templates/> 
  </xsl:element> 
</xsl:template> 
    <xsl:template match="N1">
        <xsl:variable name="value" select="."></xsl:variable>
        <xsl:choose>
            <xsl:when test="document('')//map:N1[@value = $value]">
              <div id="wellbeing-wrapper">
                <xsl:variable name="N1" select="document('')//map:N1[@value = $value]"/>
                <div class="results-copy">
                <h2 class="wellbeing-header"><xsl:value-of select="$N1/@heading"/></h2>
                <h3 class="wellbeing-result"><xsl:value-of select="$N1/@type"/></h3>
                <p class="wellbeing-copy"><xsl:apply-templates select="$N1/node()"/></p>
                </div>
                <div class="result_img"><img src="images/results/n1/{$N1/@img}" border="0" alt="" /></div>
              </div>
            </xsl:when>
            <xsl:otherwise>
                <h3>It was not possible to calculate your score. Perhaps you forgot to fill in all question fields</h3>
            </xsl:otherwise>
        </xsl:choose>
 </xsl:template>
 <xsl:template match="N2">
        <xsl:variable name="value" select="."></xsl:variable>
        <xsl:choose>
            <xsl:when test="document('')//map:N2[@value = $value]">
                <xsl:variable name="N2" select="document('')//map:N2[@value = $value]"/>
                  <div class="accordion_headings"><img src="images/results/n2/{$N2/@img}" class="img-swap" border="0" alt=""/></div>
                   <div class="accordian-child"><xsl:apply-templates select="$N2/node()"/></div>
            </xsl:when>
            <xsl:otherwise>
                <h3>It was not possible to calculate your score. Perhaps you forgot to fill in all question fields</h3>
            </xsl:otherwise>
        </xsl:choose>
 </xsl:template>
 <xsl:template match="N3">
        <xsl:variable name="value" select="."></xsl:variable>
        <xsl:choose>
            <xsl:when test="document('')//map:N3[@value = $value]">
                <xsl:variable name="N3" select="document('')//map:N3[@value = $value]"/>
                  <div class="accordion_headings"><img src="images/results/n3/{$N3/@img}" class="img-swap" border="0" alt=""/></div>
                   <div class="accordian-child"><xsl:apply-templates select="$N3/node()"/></div>
            </xsl:when>
            <xsl:otherwise>
                <h3>It was not possible to calculate your score. Perhaps you forgot to fill in all question fields</h3>
            </xsl:otherwise>
        </xsl:choose>
 </xsl:template>
  <xsl:template match="N4">
        <xsl:variable name="value" select="."></xsl:variable>
        <xsl:choose>
            <xsl:when test="document('')//map:N4[@value = $value]">
                <xsl:variable name="N4" select="document('')//map:N4[@value = $value]"/>
                  <div class="accordion_headings"><img src="images/results/n4/{$N4/@img}" class="img-swap" border="0" alt=""/></div>
                   <div class="accordian-child"><xsl:apply-templates select="$N4/node()"/></div>
            </xsl:when>
            <xsl:otherwise>
                <h3>It was not possible to calculate your score. Perhaps you forgot to fill in all question fields</h3>
            </xsl:otherwise>
        </xsl:choose>
 </xsl:template>
  <xsl:template match="N5">
        <xsl:variable name="value" select="."></xsl:variable>
        <xsl:choose>
            <xsl:when test="document('')//map:N5[@value = $value]">
                <xsl:variable name="N5" select="document('')//map:N5[@value = $value]"/>
                  <div class="accordion_headings"><img src="images/results/n5/{$N5/@img}" class="img-swap" border="0" alt=""/></div>
                   <div class="accordian-child"><xsl:apply-templates select="$N5/node()"/></div>
            </xsl:when>
            <xsl:otherwise>
                <h3>It was not possible to calculate your score. Perhaps you forgot to fill in all question fields</h3>
            </xsl:otherwise>
        </xsl:choose>
 </xsl:template>
  <xsl:template match="N6">
        <xsl:variable name="value" select="."></xsl:variable>
        <xsl:choose>
            <xsl:when test="document('')//map:N6[@value = $value]">
                <xsl:variable name="N6" select="document('')//map:N6[@value = $value]"/>
                  <div class="accordion_headings"><img src="images/results/n6/{$N6/@img}" class="img-swap" border="0" alt=""/></div>
                   <div class="accordian-child"><xsl:apply-templates select="$N6/node()"/></div>
            </xsl:when>
            <xsl:otherwise>
                <h3>It was not possible to calculate your score. Perhaps you forgot to fill in all question fields</h3>
            </xsl:otherwise>
        </xsl:choose>
 </xsl:template>
</xsl:stylesheet>

Open in new window

0
 
Geert BormansInformation ArchitectCommented:
replace template match="/" with my suggestion

Two templates with equal match attribute does NOT mean you get a duplication in result,
they simply coflict
0
 
mularamAuthor Commented:
Hi Gertone,

Apologies for the delay, been away for the week. This looks to be working well. Will post more questions if I need to separately.

Many thanks again!
0
 
Geert BormansInformation ArchitectCommented:
welcome
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.