I am trying to create a nav menu in Composite C1 for the Bootstrap framework, but I am unsure how to get submenus to show up in the menu. Here is what I have
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:in="http://www.composite.net/ns/transformation/input/1.0"
xmlns:lang="http://www.composite.net/ns/localization/1.0"
xmlns:f="http://www.composite.net/ns/function/1.0"
xmlns="http://www.w3.org/1999/xhtml"
exclude-result-prefixes="xsl in lang f">
<xsl:param name="sitemap" select="/in:inputs/in:result[#name='SitemapXml']/Page" />
<xsl:template match="/">
<html>
<head>
</head>
<body>
<div class="container">
<div class="navbar">
<div class="navbar-inner">
<ul class="nav">
<xsl:for-each select="$sitemap[#isopen='true']">
<li>
<a href="{#URL}">
<xsl:if test="#iscurrent='true'" >
<xsl:attribute name="class">active</xsl:attribute>
</xsl:if>
<xsl:value-of select="#MenuTitle" />
</a>
</li>
<xsl:apply-templates select="Page" />
</xsl:for-each>
</ul>
</div>
</div>
</div>
</body>
</html>
</xsl:template>
<xsl:template match="Page">
<xsl:if test="count(#MenuTitle)">
<li>
<a href="{#URL}">
<xsl:if test="#isopen='true'" >
<xsl:attribute name="class">active</xsl:attribute>
</xsl:if>
<xsl:value-of select="#MenuTitle" />
</a>
</li>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
I am unsure what I need to add to get the sub-menus. Suggestions?
Try out something like this
<xsl:template match="/">
<html>
<head>
</head>
<body>
<div class="container">
<div class="navbar">
<div class="navbar-inner">
<ul class="nav">
<xsl:for-each select="$sitemap[#isopen='true']">
<li>
<xsl:if test="#iscurrent='true'" >
<xsl:attribute name="class">active</xsl:attribute>
</xsl:if>
<a href="{#URL}">
<xsl:value-of select="#MenuTitle" />
</a>
</li>
<xsl:apply-templates select="Page" />
</xsl:for-each>
</ul>
</div>
</div>
</div>
</body>
</html>
</xsl:template>
<xsl:template match="Page">
<xsl:variable name="depth" select="#Depth" />
<xsl:variable name="isDropDown" select="count(./*) > 0 and $depth < 3" />
<xsl:if test="count(#MenuTitle)">
<li>
<xsl:if test="#isopen='true'" >
<xsl:attribute name="class">active</xsl:attribute>
</xsl:if>
<xsl:if test="$isDropDown" >
<xsl:attribute name="class">dropdown</xsl:attribute>
</xsl:if>
<a href="{#URL}">
<xsl:if test="$isDropDown" >
<xsl:attribute name="class">dropdown-toggle</xsl:attribute>
</xsl:if>
<xsl:if test="$isDropDown" >
<xsl:attribute name="data-toggle">dropdown</xsl:attribute>
</xsl:if>
<xsl:value-of select="#MenuTitle" />
<xsl:if test="$isDropDown" >
<b class="caret"></b>
</xsl:if>
</a>
<xsl:if test="$isDropDown">
<ul class="dropdown-menu">
<xsl:apply-templates select="./*" />
</ul>
</xsl:if>
</li>
</xsl:if>
Related
I have a xsl template that groups items by their category. Now i want to group them together inside those categories.
my xsl script:
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />
<xsl:variable name="prefix_param">udt_<xsl:value-of select="//udt:Context/udt:ModuleId" />_param</xsl:variable>
<xsl:key name="data-by-Category" match="udt:Data" use="udt:Category" />
<xsl:template match="udt:Data" mode="list">
<li>
<xsl:value-of select="udt:Subcategory" disable-output-escaping="yes" />
<xsl:value-of select="udt:Information" disable-output-escaping="yes" />
</li>
</xsl:template>
<xsl:template match="/udt:UserDefinedTable">
<xsl:for-each select="udt:Data[count(. | key('data-by-Category', udt:Category)[1]) = 1]">
<xsl:sort select="udt:Zap" />
<span>
<h1>
<xsl:value-of select="udt:Category" disable-output-escaping="yes" /> </h1>
</span>
<xsl:variable name="currentData" select="key('data-by-Category', udt:Category)" />
<xsl:if test="$currentData">
<ul>
<xsl:apply-templates select="$currentData" mode="list">
<xsl:sort select="udt:PodCategory" order="ascending" />
</xsl:apply-templates>
</ul>
</xsl:if>
</xsl:for-each>
</xsl:template>
<xsl:template name="EditLink">
<xsl:if test="udt:EditLink">
<a href="{udt:EditLink}">
<img border="0" alt="edit" src="{//udt:Context/udt:ApplicationPath}/images/edit.gif" />
</a>
</xsl:if>
</xsl:template>
The sample output i get now:
<h1>Category 1</h1>
<ul>
<li>Subcategory 1 info 1</li>
<li>Subcategory 2 info 1</li>
<li>Subcategory 2 info 2</li>
<li>Subcategory 2 info 3</li>
</ul>
<h1>Category 2</h1>
<ul>
<li>Subcategory 1 info 1</li>
<li>Subcategory 1 info 2</li>
<li>Subcategory 2 info 1</li>
</ul>
And this is the sample output i want to achieve:
<h1>Category 1</h1>
<h2>Subcategory 1</h2>
<ul>
<li>info 1</li>
</ul>
<h2>Subcategory 2</h2>
<ul>
<li>info 1</li>
<li>info 2</li>
<li>info 3</li>
</ul>
<h1>Category 2</h1>
<h2>Subcategory 1</h2>
<ul>
<li>info 1</li>
<li>info 2</li>
</ul>
<h2>Subcategory 1</h2>
<ul>
<li>info 1</li>
</ul>
I want to gtoup the items inside each group in a secondary group and display its title aswell.
Define a second key
<xsl:key name="data-by-Category-and-Subcategory" match="udt:Data" use="concat(udt:Category, '|', udt:Subcategory)" />
and then use e.g. that to identify sub groups
<xsl:template match="/udt:UserDefinedTable">
<xsl:for-each select="udt:Data[count(. | key('data-by-Category', udt:Category)[1]) = 1]">
<xsl:sort select="udt:Zap" />
<span>
<h1>
<xsl:value-of select="udt:Category" disable-output-escaping="yes" /> </h1>
</span>
<xsl:variable name="currentData" select="key('data-by-Category', udt:Category)" />
<xsl:for-each select="$currentData[generate-id() = generate-id(key('data-by-Category-and-Subcategory', concat(udt:Category, '|', udt:Subcategory))[1])]">
<h2><xsl:value-of select="udt:Subcategory"/></h2>
<xsl::variable name="$sub-group" select="key('data-by-Category-and-Subcategory', concat(udt:Category, '|', udt:Subcategory)"/>
<ul>
<xsl:apply-templates select="$sub-group" mode="list">
<xsl:sort select="udt:PodCategory" order="ascending" />
</xsl:apply-templates>
</ul>
</xsl:if>
</xsl:for-each>
</xsl:template>
I am fairly new at this and I am not sure if it is possible to do what I want to achieve here. I have 3 for-each loops that stores a number for every chapter, section and paragraph. I want to get that stored number from the previous for-each loop and display it in the nested loop, but I can't get it to work.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
<title>Table of Contents, Chapter 3</title>
</head>
<body>
<xsl:for-each select="chapter">
<tr>
<xsl:variable name="capnr">
<xsl:number value="3" format="1. "/>
</xsl:variable>
<xsl:value-of select="$capnr"/>
<xsl:value-of select="#title"/>
</tr>
<br />
<xsl:for-each select="section">
<tr>
<xsl:variable name="secnr">
<xsl:number format="1. "/>
</xsl:variable>
<xsl:value-of select="$capnr"/>
<xsl:value-of select="$secnr"/>
<xsl:value-of select="#title"/>
</tr>
<br />
<xsl:for-each select="paragraph">
<tr>
<xsl:variable name="parnr">
<xsl:number format="1 "/>
</xsl:variable>
<xsl:value-of select="$capnr"/>
<xsl:value-of select="$secnr"/>
<xsl:value-of select="$parnr"/>
<xsl:value-of select="#title"/>
</tr>
</xsl:for-each>
<br />
</xsl:for-each>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
XML:
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="ToC-3.xsl"?>
<chapter title="Chapter 3: Expressions">
<section title="Variables">
<paragraph title="Simple variables"></paragraph>
<paragraph title="Text variables"></paragraph>
<paragraph title="Remote identifiers"></paragraph>
</section>
<section title="The logical operators">
<paragraph title="Precedence of Boolean operators"></paragraph>
</section>
<section title="Designational expressions">
</section>
</chapter>
Without more details on the input and output, this should work. Of note is that the variable name is on the root, to allow all templates to access it. but since there appears to be one XSl per chapter this shouldn't be a problem.
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:variable name="capnr">
<xsl:number value="3" format="1."/>
</xsl:variable>
<xsl:template match="/">
<html>
<head>
<title>Table of Contents, Chapter 3</title>
</head>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="chapter">
<h1>
<xsl:value-of select="$capnr"/>
<xsl:value-of select="#title"/>
</h1>
<ol><xsl:apply-templates/></ol>
</xsl:template>
<xsl:template match="section">
<li>
<xsl:value-of select="$capnr"/>
<xsl:value-of select="position()"/>
<xsl:text> - </xsl:text>
<xsl:value-of select="#title"/>
<ol><xsl:apply-templates/></ol>
</li>
</xsl:template>
<xsl:template match="paragraph">
<li>
<xsl:value-of select="$capnr"/>
<xsl:value-of select="count(../preceding-sibling::*) + 1"/>
<xsl:text>.</xsl:text>
<xsl:value-of select="position()"/>
<xsl:text> - </xsl:text>
<xsl:value-of select="#title"/>
<ol><xsl:apply-templates/></ol>
</li>
</xsl:template>
</xsl:stylesheet>
The above when applied to the given input XMl gives:
<html>
<head>
<title>Table of Contents, Chapter 3</title>
</head>
<body>
<h1>3.Chapter 3: Expressions</h1>
<ol><li>3.1 - Variables<ol><li>3.1.1 - Simple variables<ol></ol>
</li>
<li>3.1.2 - Text variables<ol></ol>
</li>
<li>3.1.3 - Remote identifiers<ol></ol>
</li>
</ol>
</li>
<li>3.2 - The logical operators<ol><li>3.2.1 - Precedence of Boolean operators<ol></ol>
</li>
</ol>
</li>
<li>3.3 - Designational expressions<ol></ol>
</li>
</ol>
</body>
</html>
i have the below xslt.
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ntw="Number2Word.uri" exclude-result-prefixes="ntw">
<xsl:output method="html"/>
<xsl:template match="/">
<html>
<head>
<xsl:text disable-output-escaping="yes"><![CDATA[</meta>]]></xsl:text>
<link rel="stylesheet" href="C:\Documents and Settings\u0138039\Desktop\Per\NEW.css" type="text/css"></link>
</head>
<body>
<section class="tr_chapter">
<div class="chapter">
<xsl:apply-templates/>
</div>
</section>
</body>
</html>
</xsl:template>
<xsl:template match="case">
<xsl:apply-templates select="case.head"/>
</xsl:template>
<xsl:template match="case.head">
<div class="section-sect0">
<div class="para">
<xsl:value-of select="./party.line/party[#role='Plaintiff']"/>
</div>
</div>
<div class="section-sect0">
<div class="para">
<xsl:text disable-output-escaping="yes">V</xsl:text>
</div>
</div>
<div class="section-sect0">
<div class="para">
<xsl:value-of select="./party.line/party[#role='Defendant']"/>
</div>
</div>
<xsl:apply-templates select="case.ref.no.group | judge.line"/>
</xsl:template>
<xsl:template match="para">
<div class="para">
<xsl:apply-templates/>
</div>
</xsl:template>
<xsl:template match="case.ref.no.group">
<div class="section-sect3">
<span class="font-style-bold">Court of Appeal</span>
<xsl:text> - </xsl:text>
<xsl:value-of select="case.ref.no[1]/prefix" />
<xsl:text> Nos. </xsl:text>
<xsl:for-each select="case.ref.no">
<xsl:value-of select="number" />
<xsl:text>-</xsl:text>
<xsl:value-of select="year" />
<xsl:if test="not(position() = 2)">
</xsl:if>
</xsl:for-each>
</div>
</xsl:template>
<xsl:template match="judge.line">
<div class="section-sect3">
<xsl:for-each select="judge">
<xsl:value-of select="name"/>
<xsl:if test="not(position() = last())">
<xsl:text>,</xsl:text>
</xsl:if>
</xsl:for-each>
<xsl:text> JC</xsl:text>
</div>
<xsl:apply-templates select="following-sibling::date.group"></xsl:apply-templates>
</xsl:template>
<xsl:template match="date.group">
<div class="section-sect4">
<div class="para">
<xsl:value-of select="./date.line/date"/>
</div>
</div>
<xsl:apply-templates select="//catchwords.group"/>
</xsl:template>
<xsl:template match="catchwords.group">
<div class="y">
<xsl:for-each select="catchwords/catchword">
<xsl:choose>
<xsl:when test="#level=1"><br/>
<span class="font-style-bolditalic">
<xsl:value-of select="."/>
</span>
<xsl:text disable-output-escaping="yes">-</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:for-each select=".">
<xsl:value-of select="."></xsl:value-of>
<xsl:if test="not(position() = last()-1)">
<xsl:text disable-output-escaping="yes"> – </xsl:text>
</xsl:if>
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</div>
<xsl:apply-templates select="//headnotes"/>
</xsl:template>
<xsl:template match="headnotes/para">
<xsl:choose>
<xsl:when test="position()=1">
<div class="x">
<xsl:apply-templates></xsl:apply-templates>
</div>
</xsl:when>
<xsl:otherwise>
<div class="m">
<xsl:apply-templates/>
</div>
</xsl:otherwise>
</xsl:choose>
<xsl:apply-templates select="para.group"/>
</xsl:template>
<xsl:template match="para.group">
<div class="section-sect1">
<xsl:value-of select="./heading"/>
</div>
<xsl:for-each select="./para">
<xsl:apply-templates select="node()[not(self::label)]"/>
</xsl:for-each>
<xsl:apply-templates select="//counsel.group"/>
</xsl:template>
<xsl:template name="orderedlist" match="list">
<ol class="eng-orderedlist orderedlist">
<xsl:apply-templates select="list.item/label"/>
</ol>
</xsl:template>
<xsl:template name="orderitempara" match="list.item/label">
<li class="item">
<div class="para">
<span class="item-num">
<xsl:choose>
<xsl:when test="following-sibling::case.considered">
<xsl:apply-templates/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="."/>
</xsl:otherwise>
</xsl:choose>
</span>
<xsl:apply-templates select="parent::list.item"/>
</div>
</li>
</xsl:template>
<xsl:template match="list.item">
<xsl:variable name="a">
<xsl:value-of select="./label"/>
</xsl:variable>
<xsl:choose>
<xsl:when test="./label">
<xsl:apply-templates select="child::node()[not(self::label|case.ref)]"/>
</xsl:when>
</xsl:choose>
</xsl:template>
<xsl:template match="counsel.group" name="j">
<div class="ital">
<xsl:for-each select="./counsel.line">
<div class="para">
<xsl:value-of select="."/>
</div>
</xsl:for-each>
<xsl:text disable-output-escaping="yes">Judgment received: December 4, 2008</xsl:text>
</div>
<xsl:apply-templates select="//ref.group"/>
</xsl:template>
<xsl:template match="ref.group/leg.mentioned">
<div class="section-sect1">
<xsl:text>Legislation mentioned in the judgment</xsl:text>
</div>
<xsl:for-each select="./leg.ref">
<div class="nomar">
<xsl:value-of select="./#country"/>
</div>
<div class="para">
<xsl:value-of select="./citetitle"/>
<xsl:text>, </xsl:text>
<xsl:for-each select="./leg.ptr.group/leg.ptr">
<xsl:value-of select="."/>
<xsl:if test="not(position() = last())">
<xsl:text disable-output-escaping="yes">, </xsl:text>
</xsl:if>
</xsl:for-each>
</div>
</xsl:for-each>
<div class="section-sect1">
<xsl:text>Cases cited in the judgment</xsl:text>
</div>
<xsl:apply-templates select="//case.considered"/>
<div class="section-sec1">
<xsl:apply-templates select="//other.mentioned"/>
</div>
</xsl:template>
<xsl:template match="case.considered">
<xsl:for-each select=".">
<xsl:if test="./case.ref">
<div class="para">
<span class="font-style-italic">
<xsl:value-of select="./case.ref/citetitle[#full]"/></span>
<xsl:text> </xsl:text>
<xsl:value-of select="./case.ref/citecitation/#full"/>
</div>
</xsl:if>
</xsl:for-each>
</xsl:template>
<xsl:template match="other.mentioned/other.ref">
<div class="para">
<xsl:value-of select="./author"/>
<xsl:text>, </xsl:text>
<span class="font-style-italic">
<xsl:value-of select="./book.title"/>
</span>
<xsl:text>, </xsl:text>
<xsl:value-of select="ed_vol"/>
<xsl:value-of select="./ref_grp/reference/pageno"/>
</div>
<xsl:apply-templates select="//judgment"/>
</xsl:template>
<xsl:template match="judgment">
<div class="section-sect1">
<xsl:value-of select="./judge.block/heading"/>
</div>
<!--<xsl:for-each select="./judge.block/para.group">
--><!--<div class="para">
<span class="new">
<xsl:value-of select="./label"></xsl:value-of>
</span>
<xsl:value-of select="./text()"/>
</div>
<xsl:apply-templates select="./list"/>--><!--
<xsl:apply-templates/>
</xsl:for-each>-->
<xsl:apply-templates select="./judge.block/para.group"/>
</xsl:template>
<xsl:template match="judge.block/para.group">
<div class="section-sect1">
<xsl:apply-templates select="./heading"/>
</div>
<xsl:for-each select="./para">
<div class="para">
<span class="new">
<xsl:value-of select="./label"/></span>
<xsl:apply-templates select="./text()"/>
</div>
<xsl:if test="./block.quote">
<xsl:for-each select="./block.quote/para.group">
<div class="ali-itl">
<xsl:value-of select="./heading"/>
</div>
<xsl:for-each select="./para.group">
<div class="ali-itl">
<xsl:value-of select="./heading"/>
</div>
<div class="extract">
<div class="para">
<xsl:apply-templates select="./para"/>
</div></div>
</xsl:for-each>
</xsl:for-each>
</xsl:if>
</xsl:for-each>
<xsl:for-each select="./para.group">
<xsl:if test="./para.group">
<xsl:choose>
<xsl:when test="not(./para)">
<div class="ital">
<xsl:apply-templates select="./heading"/>
</div></xsl:when>
<xsl:otherwise>
<div class="ali-itl">
<xsl:value-of select="./heading"/>
</div>
<div class="para">
<span class="new">
<xsl:value-of select="./para/label"/>
</span>
<xsl:value-of select="./para/text()"/>
</div>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:for-each>
<xsl:if test="./block.quote">
<xsl:for-each select="./block.quote/para.group">
<div class="ali-itl">
<xsl:value-of select="./heading"/>
</div>
<xsl:for-each select="./para.group">
<div class="ali-itl">
<xsl:value-of select="./heading"/>
</div>
<div class="extract">
<div class="para">
<div class="new">
<xsl:value-of select="./para/label"/>
</div>
<xsl:apply-templates select="./para/text()"/>
</div></div>
</xsl:for-each>
</xsl:for-each>
</xsl:if>
</xsl:template>
<xsl:template match="emphasis">
<xsl:choose>
<xsl:when test="citetitle">
<span class="font-style-italic">
<xsl:apply-templates select="./list.item"/>
</span>
</xsl:when>
<xsl:when test="./#type">
<xsl:variable name="fontStyle">
<xsl:value-of select="concat('font-style-',#type)"/>
</xsl:variable>
<span class="{$fontStyle}">
<xsl:apply-templates/>
</span>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
and when i use it on my xml, the output is skipping the content in between(for example i am able to see content with number[12] and then it is directly jumping to content in number [16] and the content in between is skipped). the xml can be found in the following link.
XML Doc. please let me know where am i going wrong.
Thanks
It is really hard to tell from the information you gave, but I think your problem comes from the fact that the "para" elements with the "labels" 13-15 actually lie within a nested second para.group element within the first one.
Your template probably only matches "para" elements directly within "para.group" elements, but not nested "para.group" elements.
As an outsider, it's basically impossible to tell without investing way too much time in analyzing the huge input you gave, which is probably why you didn't receive another answer up until now.
I have this xsl bellow :
<xsl:template match="/" xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:SharePoint="Microsoft.SharePoint.WebControls">
<div id="vtab">
<ul>
<xsl:call-template name="dvt_1.body"/>
</ul>
</div>
</xsl:template>
<xsl:template name="dvt_1.body">
<xsl:for-each select="/dsQueryResponse/Rows/Row[generate-id(.)=generate-id(key('TitleKey', #Title))]">
<li>
<xsl:value-of select="#Title"/>
</li>
<xsl:variable name="thisClassification" select="#Title" />
<div>
<xsl:for-each select="../Row[#Title = $thisClassification]">
<xsl:value-of select="#Model"/>
</xsl:for-each>
</div>
</xsl:for-each>
</xsl:template>
I would like have this output:
<div id="vtab">
<ul>
<li>HTC</li>
<li>Nokia</li>
</ul>
<div>HTC Sensation 345-HTC Ev</div>
<div>Nokia</div>
</div>
But now this is what i'm getting
<div id="vtab">
<ul>
<li>HTC</li>
<div>HTC Sensation 345HTC Evo</div>
<li>Nokia</li>
<div>Nokia</div>
</ul>
</div>
How can i exit the UL element and start the DIV element.
Thanks alot
It is not optimal, but consider making two loops something like the following:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<div id="vtab">
<xsl:call-template name="LOOP_1"/>
<xsl:call-template name="LOOP_2"/>
</div>
</xsl:template>
<xsl:template name="LOOP_1">
<ul>
<xsl:for-each select="/dsQueryResponse/Rows/Row[generate-id(.)=generate-id(key('TitleKey', #Title))]">
<li>
<xsl:value-of select="#Title"/>
</li>
<xsl:variable name="thisClassification" select="#Title"/>
<div>
<xsl:for-each select="../Row[#Title = $thisClassification]">
<xsl:value-of select="#Model"/>
</xsl:for-each>
</div>
</xsl:for-each>
</ul>
</xsl:template>
<xsl:template name="LOOP_2">
<div>
<xsl:for-each select="/dsQueryResponse/Rows/Row[generate-id(.)=generate-id(key('TitleKey', #Title))]">
<xsl:variable name="thisClassification" select="#Title"/>
<div>
<xsl:for-each select="../Row[#Title = $thisClassification]">
<xsl:value-of select="#Model"/>
</xsl:for-each>
</div>
</xsl:for-each>
</div>
</xsl:template>
</xsl:stylesheet>
I am not sure of your requirements, but it may be more efficient to review the desired output, and output nested lists and format it using CSS rather than creating separate loops
I have converted mny stylesheet to use apply templates instead of call templates and it worked fine for my other styesheet, which was more complicated, but this one doesn't seem to work even thought it is a much simpler template.
All that it outputs is the sex node and the userlevel node. I think it has to do with my Xpath.
All i want is to output the < user > information, nothing else
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template name="hoo" match="/">
<html>
<head>
<title>Registered Members</title>
<link rel="stylesheet" type="text/css" href="user.css" />
</head>
<body>
<h1>Registered Members</h1>
<xsl:for-each select="folktask/member/user">
<div class="userdiv">
<xsl:apply-templates/>
</div>
</xsl:for-each>
</body>
</html>
</xsl:template>
<xsl:template match="folktask/member/user">
<xsl:apply-templates select="#id"/>
<xsl:apply-templates select="personal/name"/>
<xsl:apply-templates select="personal/address1"/>
<xsl:apply-templates select="personal/city"/>
<xsl:apply-templates select="personal/county"/>
<xsl:apply-templates select="personal/postcode"/>
<xsl:apply-templates select="personal/telephone"/>
<xsl:apply-templates select="personal/mobile"/>
<xsl:apply-templates select="personal/email"/>
<xsl:apply-templates select="personal"/>
<xsl:apply-templates select="account/username"/>
<xsl:apply-templates select="account"/>
</xsl:template>
<xsl:template match="#id">
<div class="heading bold"><h2>USER ID: <xsl:value-of select="." /></h2></div>
</xsl:template>
<xsl:template match="personal/name">
<div class="small bold">NAME:</div>
<div class="large"><xsl:value-of select="." /></div>
</xsl:template>
<xsl:template match="personal/address1">
<div class="small bold">ADDRESS:</div>
<div class="large"><xsl:value-of select="." /></div>
</xsl:template>
<xsl:template match="personal/city">
<div class="small bold">CITY:</div>
<div class="large"><xsl:value-of select="." /></div>
</xsl:template>
<xsl:template match="personal/county">
<div class="small bold">COUNTY:</div>
<div class="large"><xsl:value-of select="." /></div>
</xsl:template>
<xsl:template match="personal/postcode">
<div class="small bold">POSTCODE:</div>
<div class="large"><xsl:value-of select="." /></div>
</xsl:template>
<xsl:template match="personal/telephone">
<div class="small bold">TELEPHONE:</div>
<div class="large"><xsl:value-of select="." /></div>
</xsl:template>
<xsl:template match="personal/mobile">
<div class="small bold">MOBILE:</div>
<div class="large"><xsl:value-of select="." />
</div>
</xsl:template>
<xsl:template match="personal/email">
<div class="small bold">EMAIL:</div>
<div class="large">
<xsl:element name="a">
<xsl:attribute name="href">
<xsl:text>mailto:</xsl:text>
<xsl:value-of select="." />
</xsl:attribute>
<xsl:value-of select="." />
</xsl:element>
</div>
</xsl:template>
<xsl:template match="personal">
<div class="small bold">SEX:</div>
<div class="colored bold">
<xsl:choose>
<xsl:when test="sex='Male'">
<div class="sex male"><xsl:value-of select="sex/."/></div>
</xsl:when>
<xsl:otherwise>
<div class="sex female"><xsl:value-of select="sex/."/></div>
</xsl:otherwise>
</xsl:choose>
</div>
</xsl:template>
<xsl:template match="account/username">
<div class="small bold">USERNAME:</div>
<div class="large"><xsl:value-of select="." /></div>
</xsl:template>
<xsl:template match="account">
<div class="small bold">ACCOUNT TYPE:</div>
<div class="colored ">
<xsl:choose>
<xsl:when test="userlevel='1'">
<div class="nml bold">Normal User</div>
</xsl:when>
<xsl:when test="userlevel='2'">
<div class="vol bold">Volunteer</div>
</xsl:when>
<xsl:when test="userlevel='3'">
<div class="org bold">Organiser</div>
</xsl:when>
<xsl:otherwise>
<div class="name adm bold">Administrator</div>
</xsl:otherwise>
</xsl:choose>
</div>
</xsl:template>
</xsl:stylesheet>
and some of my xml
<?xml version="1.0" encoding="ISO-8859-1" ?>
<?xml-stylesheet type="text/xsl" href="users.xsl"?>
<folktask xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:noNamespaceSchemaLocation="folktask.xsd">
<member>
<user id="1">
<personal>
<name>Abbie Hunt</name>
<sex>Female</sex>
<address1>108 Access Road</address1>
<address2></address2>
<city>Wells</city>
<county>Somerset</county>
<postcode>BA5 8GH</postcode>
<telephone>01528927616</telephone>
<mobile>07085252492</mobile>
<email>adrock#gmail.com</email>
</personal>
<account>
<username>AdRock</username>
<password>269eb625e2f0cf6fae9a29434c12a89f</password>
<userlevel>4</userlevel>
<signupdate>2010-03-26T09:23:50</signupdate>
</account>
</user>
<volunteer id="1">
<roles></roles>
<region>South West</region>
</volunteer>
</member>
<member>
<user id="2">
<personal>
<name>Aidan Harris</name>
<sex>Male</sex>
<address1>103 Aiken Street</address1>
<address2></address2>
<city>Chichester</city>
<county>Sussex</county>
<postcode>PO19 4DS</postcode>
<telephone>01905149894</telephone>
<mobile>07784467941</mobile>
<email>ambientexpert#yahoo.co.uk</email>
</personal>
<account>
<username>AmbientExpert</username>
<password>8e64214160e9dd14ae2a6d9f700004a6</password>
<userlevel>2</userlevel>
<signupdate>2010-03-26T09:23:50</signupdate>
</account>
</user>
<volunteer id="2">
<roles>Van Driver,gas Fitter</roles>
<region>South Central</region>
</volunteer>
</member>
</folktask>
The problem is in this code:
<xsl:for-each select="folktask/member/user">
<div class="userdiv">
<xsl:apply-templates/>
</div>
</xsl:for-each>
This applies templates to all children of the current user element -- not to the user element.
As result, the template matching user is not selected.
The children of user are personal and account.
The templates matching these elements are selected and they produce their output.
Solution: Quite some cleanup is necessary, but the first obvious step is to replace the above code with:
<xsl:apply-templates select="folktask/member/user"/>
You'll also have to move the div from the deleted body of <xsl:for-each> into the template matching folktask/member/user.
The corrected XSLT code is:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template name="hoo" match="/">
<html>
<head>
<title>Registered Members</title>
<link rel="stylesheet" type="text/css" href="user.css" />
</head>
<body>
<h1>Registered Members</h1>
<xsl:apply-templates select="folktask/member/user"/>
</body>
</html>
</xsl:template>
<xsl:template match="folktask/member/user">
<div class="userdiv">
<xsl:apply-templates select="#id"/>
<xsl:apply-templates select="personal/name"/>
<xsl:apply-templates select="personal/address1"/>
<xsl:apply-templates select="personal/city"/>
<xsl:apply-templates select="personal/county"/>
<xsl:apply-templates select="personal/postcode"/>
<xsl:apply-templates select="personal/telephone"/>
<xsl:apply-templates select="personal/mobile"/>
<xsl:apply-templates select="personal/email"/>
<xsl:apply-templates select="personal"/>
<xsl:apply-templates select="account/username"/>
<xsl:apply-templates select="account"/>
</div>
</xsl:template>
<xsl:template match="#id">
<div class="heading bold"><h2>USER ID: <xsl:value-of select="." /></h2></div>
</xsl:template>
<xsl:template match="personal/name">
<div class="small bold">NAME:</div>
<div class="large"><xsl:value-of select="." /></div>
</xsl:template>
<xsl:template match="personal/address1">
<div class="small bold">ADDRESS:</div>
<div class="large"><xsl:value-of select="." /></div>
</xsl:template>
<xsl:template match="personal/city">
<div class="small bold">CITY:</div>
<div class="large"><xsl:value-of select="." /></div>
</xsl:template>
<xsl:template match="personal/county">
<div class="small bold">COUNTY:</div>
<div class="large"><xsl:value-of select="." /></div>
</xsl:template>
<xsl:template match="personal/postcode">
<div class="small bold">POSTCODE:</div>
<div class="large"><xsl:value-of select="." /></div>
</xsl:template>
<xsl:template match="personal/telephone">
<div class="small bold">TELEPHONE:</div>
<div class="large"><xsl:value-of select="." /></div>
</xsl:template>
<xsl:template match="personal/mobile">
<div class="small bold">MOBILE:</div>
<div class="large"><xsl:value-of select="." />
</div>
</xsl:template>
<xsl:template match="personal/email">
<div class="small bold">EMAIL:</div>
<div class="large">
<xsl:element name="a">
<xsl:attribute name="href">
<xsl:text>mailto:</xsl:text>
<xsl:value-of select="." />
</xsl:attribute>
<xsl:value-of select="." />
</xsl:element>
</div>
</xsl:template>
<xsl:template match="personal">
<div class="small bold">SEX:</div>
<div class="colored bold">
<xsl:choose>
<xsl:when test="sex='Male'">
<div class="sex male"><xsl:value-of select="sex/."/></div>
</xsl:when>
<xsl:otherwise>
<div class="sex female"><xsl:value-of select="sex/."/></div>
</xsl:otherwise>
</xsl:choose>
</div>
</xsl:template>
<xsl:template match="account/username">
<div class="small bold">USERNAME:</div>
<div class="large"><xsl:value-of select="." /></div>
</xsl:template>
<xsl:template match="account">
<div class="small bold">ACCOUNT TYPE:</div>
<div class="colored ">
<xsl:choose>
<xsl:when test="userlevel='1'">
<div class="nml bold">Normal User</div>
</xsl:when>
<xsl:when test="userlevel='2'">
<div class="vol bold">Volunteer</div>
</xsl:when>
<xsl:when test="userlevel='3'">
<div class="org bold">Organiser</div>
</xsl:when>
<xsl:otherwise>
<div class="name adm bold">Administrator</div>
</xsl:otherwise>
</xsl:choose>
</div>
</xsl:template>
</xsl:stylesheet>
Running the corrected transformation now produces the intended results:
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-16">
<title>Registered Members</title>
<link rel="stylesheet" type="text/css" href="user.css">
</head>
<body>
<h1>Registered Members</h1>
<div class="userdiv">
<div class="heading bold"><h2>USER ID: 1</h2></div>
<div class="small bold">NAME:</div>
<div class="large">Abbie Hunt</div>
<div class="small bold">ADDRESS:</div>
<div class="large">108 Access Road</div>
<div class="small bold">CITY:</div>
<div class="large">Wells</div>
<div class="small bold">COUNTY:</div>
<div class="large">Somerset</div>
<div class="small bold">POSTCODE:</div>
<div class="large">BA5 8GH</div>
<div class="small bold">TELEPHONE:</div>
<div class="large">01528927616</div>
<div class="small bold">MOBILE:</div>
<div class="large">07085252492</div>
<div class="small bold">EMAIL:</div>
<div class="large">adrock#gmail.com</div>
<div class="small bold">SEX:</div>
<div class="colored bold">
<div class="sex female">Female</div>
</div>
<div class="small bold">USERNAME:</div>
<div class="large">AdRock</div>
<div class="small bold">ACCOUNT TYPE:</div>
<div class="colored ">
<div class="name adm bold">Administrator</div>
</div>
</div>
<div class="userdiv">
<div class="heading bold"><h2>USER ID: 2</h2></div>
<div class="small bold">NAME:</div>
<div class="large">Aidan Harris</div>
<div class="small bold">ADDRESS:</div>
<div class="large">103 Aiken Street</div>
<div class="small bold">CITY:</div>
<div class="large">Chichester</div>
<div class="small bold">COUNTY:</div>
<div class="large">Sussex</div>
<div class="small bold">POSTCODE:</div>
<div class="large">PO19 4DS</div>
<div class="small bold">TELEPHONE:</div>
<div class="large">01905149894</div>
<div class="small bold">MOBILE:</div>
<div class="large">07784467941</div>
<div class="small bold">EMAIL:</div>
<div class="large">ambientexpert#yahoo.co.uk</div>
<div class="small bold">SEX:</div>
<div class="colored bold">
<div class="sex male">Male</div>
</div>
<div class="small bold">USERNAME:</div>
<div class="large">AmbientExpert</div>
<div class="small bold">ACCOUNT TYPE:</div>
<div class="colored ">
<div class="vol bold">Volunteer</div>
</div>
</div>
</body>
</html>
There are many errors. The main are the following:
You cannot apply template to attribute
If you write <xsl:apply-templates select="personal/name"/>, you might write <xsl:template match="name"> to match it. (And also for other nodes)