I've got a curious item, I'm trying to enumerate through an xml file with my XSLT transform, however I'm after putting a for-each loop into the code my records are not pulling any details (anymore). Help!
XSLT
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html" indent="yes" omit-xml-declaration="yes"/>
<xsl:variable name="pathid" select="montage/path" />
<xsl:variable name="outputstr" select="''" />
<xsl:template match="vista">
<xsl:variable name="pathid" select="path" />
<html>
<body>
<div align="center">
<table border="0" cellpadding="0" cellspacing="0" width="800" height="200">
<xsl:apply-templates select="item" />
</table>
</div>
</body>
</html>
</xsl:template>
<xsl:template match="item">
<xsl:variable name="monid" select="mon" />
<!--<xsl:value-of select="format-number(position(), '#')" />-->
<xsl:variable name="outputstr" select="file" />
<xsl:choose>
<xsl:when test="position() >= 0 and 4 > position()">
<tr height="200">
<xsl:for-each select="item">
<td width="157" height="108" valign="top">
<xsl:attribute name="height">
<xsl:value-of select="'200'"/>
</xsl:attribute>
<a>
<xsl:attribute name="href">
<xsl:value-of select="$pathid" />
<xsl:value-of select="thepage" />
</xsl:attribute>
<img>
<xsl:attribute name="src">
<xsl:value-of select="concat(substring-before($outputstr,'abc'),$pathid)"/>
<xsl:value-of select="$outputstr" />
</xsl:attribute>
</img>
</a>
</td>
</xsl:for-each>
</tr>
</xsl:when>
</xsl:choose>
<xsl:attribute name="id">mon</xsl:attribute>
</xsl:template>
</xsl:stylesheet>
XML
<?xml version="1.0"?>
<vista>
<lastupdate>14/12/2010 14:32</lastupdate>
<path>C:\</path>
<item>
<thepage>00000657.html</thepage>
<heading>heading1</heading>
<file>test123.png</file>
<description>df bhdf hdfhdf hdfh he rher herh df bdf bdfb df rfbd bd</description>
</item>
<item>
<thepage>00000660.html</thepage>
<heading>heading2</heading>
<file>test456.jpg</file>
<description>reh erh erherh erh erher herh</description>
</item>
</vista>
Outputted HTML
<html>
<body>
<div align="center">
<table border="0" cellpadding="0" cellspacing="0" width="800" height="200">
<tr height="200"></tr>
<tr height="200"></tr>
<tr height="200"></tr>
<tr height="100"></tr>
<tr height="100"></tr>
<tr height="100"></tr>
<tr height="100"></tr>
</table>
</div>
</body>
</html>
The line <xsl:for-each select="item"> - I think you're already in "item". You can't select it again.
You already have an item template - why do you need to for-each inside it?
I expect this to fail, as item nodes do not contain item nodes.
Related
I have a xml below
<Report>
<rl>
<id>12345;12346</id>
<activity>a2/a3</activity>
<result>r2/r3</result>
<operator>test</operator>
<timestamp>12/18/2014 3:51:19 PM</timestamp>
<quantity>2</quantity>
</rl>
<rl>
<id>22345;22346</id>
<activity>a3/a4</activity>
<result>r3/r4</result>
<operator>test</operator>
<timestamp>12/18/2014 3:51:19 PM</timestamp>
<quantity>2</quantity>
</rl>
</Report>
and for my xsl,
<table border="1" style="border-width: 1px" width="90%" bordercolor="#C0C0C0" align="center">
<tr>
<th width="5%" align="center">
<font color="#000000" face="Verdana" size="3">Index</font>
</th>
<th width="15%" align="center">
<font color="#000000" face="Verdana" size="3">ID A:</font>
</th>
<th width="15%" align="center">
<font color="#000000" face="Verdana" size="3">ID B:</font>
</th>
</tr>
<xsl:for-each select="Report/rl">
<tr height="25">
<td width="5%" align="center" >
<font color="#000000" face="Verdana" size="2">
<xsl:value-of select="position()" />
</font>
</td>
<td align="center">
<font color="#000000" face="Verdana" size="2">
<xsl:value-of select="idA" />
</font>
</td>
<td align="center">
<font color="#000000" face="Verdana" size="2">
<xsl:value-of select="idB" />
</font>
</td>
</tr>
</xsl:for-each>
</table>
For 1st rl, there is 12345:12346 for tag, I want to split them into 12345 and 12346 and show them in the 'idA' and 'idB'. How should I do that?
My xslt version is 1.0.
Assuming there are always exactly two values, separated by a semicolon, use:
<xsl:value-of select="substring-before(id, ';')"/>
to populate the idA cell, and:
<xsl:value-of select="substring-after(id, ';')"/>
to populate the idB cell.
Added:
For the same example as posted, can you elaborate more about the
'recursive named template'?
The solution using a recursive named template would look something like this:
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" omit-xml-declaration="yes" version="1.0" encoding="utf-8" indent="yes"/>
<xsl:template match="/Report">
<table border="1">
<tr>
<th>Index</th>
<th>ID A</th>
<th>ID B</th>
</tr>
<xsl:apply-templates select="rl"/>
</table>
</xsl:template>
<xsl:template match="rl">
<tr>
<td>
<xsl:value-of select="position()" />
</td>
<xsl:call-template name="tokenize">
<xsl:with-param name="text" select="id"/>
</xsl:call-template>
</tr>
</xsl:template>
<xsl:template name="tokenize">
<xsl:param name="text"/>
<xsl:param name="delimiter" select="';'"/>
<td>
<xsl:value-of select="substring-before(concat($text, $delimiter), $delimiter)"/>
</td>
<xsl:if test="contains($text, $delimiter)">
<!-- recursive call -->
<xsl:call-template name="tokenize">
<xsl:with-param name="text" select="substring-after($text, $delimiter)"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
Note that for the header we assume that the number of columns is known beforehand. Otherwise you'd have to use a similar recursive template to generate the header cells too.
Check this example
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
>
<xsl:output method="xml" indent="yes"/>
<xsl:template match="*">
<xsl:for-each select="rl">
<node>
<idA>
<xsl:value-of select="substring-before(id,';')"/>
</idA>
<idB>
<xsl:value-of select="substring-after(id,';')"/>
</idB>
</node>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
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 am trying to create a loop inside a template. I found 2 methods, but both of them did not work:
Method 1:
<xsl:template name="recurse_till_ten">
<xsl:param name="num">1</xsl:param> <!-- param has initial value of
1 -->
<xsl:if test="not($num = 10)">
...do something
<xsl:call-template name="recurse_till_ten">
<xsl:with-param name="num">
<xsl:value-of select="$num + 1">
</xsl:with-param>
</xsl:call-template>
</xsl:if>
</xsl:template>
Method 2:
<xsl:variable name="count" select="'5'"/>
<xsl:for-eachselect="(//*)[position()<=$count]">
<!-- Repeated content Here -->
<!-- use position() to get loop index -->
<xsl:value-of select="position()"/>.<br/>
</xsl:for-each>
Method 1 gave the following error:
element template only allowed as child of stylesheet
Method 2 did not show anything since I am using another position() for displaying some outputs:
<td>
<xsl:if test='buildid = /cdash/etests/etest/buildid'>
<xsl:variable name='index'
select='2*count(preceding-sibling::build[buildid = /cdash/etests/etest/buildid])+position()' />
<xsl:value-of select="/cdash/etests/etest[position()=$index]/value" />
</xsl:if>
</td>
How can I create a loop that should call the code between two times?
Original XSL:
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version='1.0'>
<xsl:include href="header.xsl"/>
<xsl:include href="footer.xsl"/>
<xsl:include href="local/header.xsl"/>
<xsl:include href="local/footer.xsl"/>
<xsl:output method="xml" indent="yes" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" />
<xsl:template match="/">
<html>
<head>
<title><xsl:value-of select="cdash/title"/></title>
<meta name="robots" content="noindex,nofollow" />
<link rel="StyleSheet" type="text/css">
<xsl:attribute name="href">
<xsl:value-of select="cdash/cssfile"/>
</xsl:attribute>
</link>
<xsl:call-template name="headscripts"/>
<!-- Include JavaScript -->
<script src="javascript/cdashTestGraph.js" type="text/javascript" charset="utf-8"></script>
</head>
<body bgcolor="#ffffff">
<xsl:choose>
<xsl:when test="/cdash/uselocaldirectory=1">
<xsl:call-template name="header_local"/>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="header"/>
</xsl:otherwise>
</xsl:choose>
<br/>
<h3>Testing summary for
<u><xsl:value-of select="cdash/testName"/></u>
performed between <xsl:value-of select="cdash/builds/teststarttime"/> and <xsl:value-of select="cdash/builds/testendtime"/>
</h3>
<!-- Failure Graph -->
<a>
<xsl:attribute name="href">javascript:showtestfailuregraph_click('<xsl:value-of select="/cdash/dashboard/projectid"/>','<xsl:value-of select="/cdash/testName"/>','<xsl:value-of select="/cdash/builds/currentstarttime"/>')</xsl:attribute>
Show Test Failure Trend
</a>
<div id="testfailuregraphoptions"></div>
<div id="testfailuregraph"></div>
<center>
<div id="testfailuregrapholder"></div>
</center>
<br/>
<!-- Test Summary table count(preceding-sibling::etests[columnname]) + 1 count(/cdash/etests/columnname) + 1 /cdash/etests/columnname[position()=$index] -->
<table id="testSummaryTable" cellspacing="0" cellpadding="3" class="tabb">
<thead>
<tr class="table-heading1">
<th id="sort_0">Site</th>
<th id="sort_1">Build Name</th>
<th id="sort_2">Build Stamp</th>
<th id="sort_3">Status</th>
<th id="sort_4">Time (s)</th>
<th id="sort_5">Build Revision</th>
<xsl:for-each select='/cdash/etests/columnname'>
<xsl:variable name='index_col' select='count(preceding-sibling::columnname) + 1'/>
<th><xsl:attribute name="id">
<xsl:value-of select="$index_col" />
</xsl:attribute>
<xsl:value-of select="/cdash/etests/columnname[position()=$index_col]" /></th>
</xsl:for-each>
</tr>
</thead>
<xsl:for-each select="cdash/builds/build">
<tr>
<td>
<xsl:value-of select="site"/>
</td>
<td><a>
<xsl:attribute name="href">
<xsl:value-of select="buildLink"/>
</xsl:attribute>
<xsl:value-of select="buildName"/>
</a></td>
<td>
<xsl:value-of select="buildStamp"/>
</td>
<td>
<xsl:attribute name="class">
<xsl:value-of select="statusclass"/>
</xsl:attribute>
<a>
<xsl:attribute name="href">
<xsl:value-of select="testLink"/>
</xsl:attribute>
<xsl:value-of select="status"/>
</a>
</td>
<td>
<xsl:value-of select="time"/>
</td>
<td>
<a><xsl:attribute name="href"><xsl:value-of select="update/revisionurl"/></xsl:attribute>
<xsl:value-of select="update/revision"/>
</a>
</td>
<!-- NEW ADDITIONNN !!!!!!!!!!! -->
<td>
<xsl:if test='buildid = /cdash/etests/etest/buildid'>
<xsl:variable name='index'
select='2*count(preceding-sibling::build[buildid = /cdash/etests/etest/buildid])+1' />
<xsl:value-of select="/cdash/etests/etest[position()=$index]/value" />
</xsl:if>
</td>
<td>
<xsl:if test='buildid = /cdash/etests/etest/buildid'>
<xsl:variable name='index'
select='2*count(preceding-sibling::build[buildid = /cdash/etests/etest/buildid])+2' />
<xsl:value-of select="/cdash/etests/etest[position()=$index]/value" />
</xsl:if>
</td>
<!-- NEW ADDITIONNN !!!!!!!!!!! -->
</tr>
</xsl:for-each>
</table>
<br/>
<!-- FOOTER -->
<br/>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Original XML:
<?xml version="1.0" encoding="utf-8"?><cdash><title>Title</title><cssfile>cdash.css</cssfile><version>2.1.0</version><dashboard>
<nextdate>2012-09-18</nextdate>
</menu><etests>
<columnname>LoadTime</columnname>
<etest>
<name>LoadTime</name><buildid>19390</buildid><value>1777</value>
</etest>
<columnname>Median</columnname>
<etest>
<name>Median</name><buildid>19390</buildid><value>1508</value>
</etest>
<etest>
<name>LoadTime</name><buildid>19389</buildid><value>676</value>
</etest>
<etest>
<name>Median</name><buildid>19389</buildid><value>868</value>
</etest>
</etests>
<builds>
<projectid>1</projectid><currentstarttime>1347825600</currentstarttime><teststarttime>2012-09-16T22:00:00</teststarttime><testendtime>2012-09-17T22:00:00</testendtime>
<build>
<buildName>Linux</buildName><buildStamp>20120916-2100-Nightly</buildStamp><time>174.86</time><buildid>19390</buildid><buildLink>viewTest.php?buildid=19390</buildLink><testLink>testDetails.php?test=289784&build=19390</testLink><status>Passed</status><statusclass>normal</statusclass></build>
<build>
<buildName>Linux</buildName><buildStamp>20120916-2100-Nightly</buildStamp><time>174.86</time><buildid>19389</buildid><buildLink>viewTest.php?buildid=19389</buildLink><testLink>testDetails.php?test=289784&build=19389</testLink><status>Passed</status><statusclass>normal</statusclass></build>
</builds>
<generationtime>0.201</generationtime></cdash></xml>
I'm not sure what you are trying to do in your method 2 process so I'm going to focus on the first one.
You will want to update the code to something like this
<xsl:template name="recurse_till_ten">
<xsl:param name="num" />
<xsl:if test="not($num = 10)">
...do something
<xsl:call-template name="recurse_till_ten">
<xsl:with-param name="num" select="$num + 1" />
</xsl:call-template>
</xsl:if>
</xsl:template>
The only important change I made was not setting the variable in the loop. By setting it in the loop then you are always setting num = 1 which would make for an infinite loop.
So then you would call it somewhere else in your template by doing this.
<xsl:call-template name="recurse_till_ten">
<xsl:with-param name="num" select="number('1')" />
</xsl:call-template>
That should allow you to loop until the variable hits 10.
I have input xml of the form
<content xml:lang="en" xmlns:w="http://www.w.com/sch/W">
<w:firstRowHeader>true</w:firstRowHeader>
<w:firstColumnHeader>true</w:firstColumnHeader>
<w:customTable>
<w:tableContent>
<w:row>
<w:cell>
<w:spanInfo backgroundColor="Yellow" columnWidth="5" isRowHeader="true"/>
<text>ghnmghmg</text>
</w:cell>
<w:cell>
<w:spanInfo backgroundColor="Yellow" isRowHeader="false"/>
<text>ghmhgmgm</text>
</w:cell>
</w:row>
<w:row>
<w:cell>
<w:spanInfo backgroundColor="Yellow" columnWidth="5" isRowHeader="false"/>
<text>vj</text>
</w:cell>
<w:cell>
<w:spanInfo columnWidth="5" isRowHeader="true"/>
<text>mm</text>
</w:cell>
</w:row>
</w:tableContent>
</w:customTable>
</content>
This needs to be transformed to a xml in which:
w:tableContent mapped to tablecontent and
then under tablecontent tag 'table','tbody' tags are created
w:row mapped to tr tag
w:cell mapped to td tag
and conditions are like
if only 1st w:cell element in w:row has an attribute isRowHeader as "true" then every 'td' element under its respective 'tr' tag should contain a 'strong' tag and ignore 2nd w:cell's isRowHeader
if w:firstRowHeader is 'true' then transformed table should have 1st row text in bold, i.e., every 'td' tag in 1st row of table should contain 'strong' tag
if w:firstColumnHeader is 'true' then transformed table should have 1st column text in bold, i.e., every tr tag's 1st 'td' tag of table should contain 'strong' tag
Transformed xml:
<content>
<tablecontent>
<table cellspacing="1" cellpadding="1" border="1" style="WIDTH: 100%" title="Title" xmlns="http://www.w3.org/1999/xhtml">
<tbody>
<tr>
<td style="BACKGROUND-COLOR: Yellow; WIDTH: 5%"><strong>ghnmghmg</strong></td>
<td style="BACKGROUND-COLOR: Yellow"><strong>ghmhgmgm</strong></td>
</tr>
<tr>
<td style="BACKGROUND-COLOR: Yellow; WIDTH: 5%">vj</td>
<td style="WIDTH: 5%">mm</td>
</tr>
</tbody>
</table>
</tablecontent>
</content>
This is the xslt template that i have tried but cant figure out how to implement these 'strong' tags in it...
XSLT:
<xsl:template match="w:tableContent">
<xsl:variable name="var3" select="../w:firstRowHeader"/>
<xsl:variable name="var4" select="../w:firstColumnHeader"/>
<tablecontent>
<table cellspacing="1" cellpadding="1" border="1" style="WIDTH: 100%" title="Title" xmlns="http://www.w3.org/1999/xhtml" >
<tbody>
<xsl:for-each select="child::*">
<xsl:choose>
<xsl:when test="name()='w:row'">
<tr>
<xsl:for-each select="child::*">
<xsl:choose>
<xsl:when test="name()='w:cell'">
<td>
<xsl:for-each select="child::*">
<xsl:choose>
<xsl:when test="name()='w:spanInfo'">
<xsl:variable name="var8" select="#backgroundColor" />
<xsl:variable name="var9" select="#columnWidth" />
<xsl:variable name="var10" select="#isRowHeader" />
<xsl:if test="$var8!='' or $var9!=''">
<xsl:attribute name="style">
<xsl:if test="$var8!='' and $var9!=''">
<xsl:value-of select="concat('BACKGROUND-COLOR: ',$var8,'; WIDTH: ',$var9,'%')" />
</xsl:if>
<xsl:if test="$var8!='' and not($var9)">
<xsl:value-of select="concat('BACKGROUND-COLOR: ',$var8)" />
</xsl:if>
<xsl:if test="not($var8) and $var9!=''">
<xsl:value-of select="concat('WIDTH: ',$var9,'%')" />
</xsl:if>
</xsl:when>
<xsl:when test="name()='text'">
<xsl:if test="../w:spanInfo/#isRowHeader='true'">
<strong><xsl:value-of select="." /></strong>
</xsl:if>
<xsl:if test="../w:spanInfo/#isRowHeader!='true' or not(../w:spanInfo/#isRowHeader) ">
<xsl:value-of select="." />
</xsl:if>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</td>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</tr>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</tbody>
</table>
</tablecontent>
</xsl:template>
But the above template adds 'strong' tags to the cells which has only w:spanInfo's 'isRowHeader' attribute as 'true'. But I require to get 'strong' tag to be added to 2nd cell content also irrespective of its w:spanInfo's 'isRowHeader' attribute's value, provided if 1st cell already has 'isRowHeader' attribute as 'true'.
This XSLT 1.0 style-sheet ...
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:w="http://www.w.com/sch/W">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<content>
<xsl:apply-templates select="*/*/w:tableContent"/>
</content>
</xsl:template>
<xsl:template match="w:tableContent">
<table cellspacing="1" cellpadding="1" border="1" style="WIDTH: 100%" title="Title" xmlns="http://www.w3.org/1999/xhtml">
<tbody>
<xsl:apply-templates select="w:row" />
</tbody>
</table>
</xsl:template>
<xsl:template match="w:row">
<tr>
<xsl:apply-templates select="w:cell" />
</tr>
</xsl:template>
<xsl:template match="w:cell">
<xsl:variable name="style">
<xsl:if test="w:spanInfo/#backgroundColor">
<xsl:value-of select="concat('BACKGROUND-COLOR: ',w:spanInfo/#backgroundColor)" />
</xsl:if>
<xsl:if test="w:spanInfo/#columnWidth">
<xsl:if test="w:spanInfo/#backgroundColor">
<xsl:value-of select="'; '" />
</xsl:if>
<xsl:value-of select="concat('WIDTH: ',w:spanInfo/#columnWidth,'%')" />
</xsl:if>
</xsl:variable>
<td>
<xsl:if test="$style">
<xsl:attribute name="style"><xsl:value-of select="$style" /></xsl:attribute>
</xsl:if>
<xsl:apply-templates select="text" />
</td>
</xsl:template>
<xsl:template match="w:cell/text[
not( ../../preceding-sibling::w:row) and (/*/w:firstRowHeader='true')
or
not( ../preceding-sibling::w:cell) and (/*/w:firstColumnHeader='true')
or
(../preceding-sibling::w:cell[last()]/w:spaninfo/#isRowHeader='true')
]">
<strong><xsl:call-template name="default-rendering-of-text" /></strong>
</xsl:template>
<xsl:template match="text" name="default-rendering-of-text">
<xsl:value-of select="." />
</xsl:template>
</xsl:stylesheet>
... should satisfy your rules. The 3 conditions that you have set for bold/strong rendering are made plainly evident by the predicate of the match condition for text elements (near the end of the style-sheet). By avoiding unnecessary xsl:for-each we can use a simpler, more modular and more readable template based solution.
Need some help: I want to only pull back the results for a specific ItemId, so if i wanted the only data for ItemId how could I adapt the template below?
I've tried for about 2 hours without any luck...
Here is a sample of my XML:
This Xslt only brings the item with ItemId value equal to 2075.
Notice I added [ItemInfo/PeriodAttendanceInfo/ItemId=2075].
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
>
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<xsl:call-template name="dvt_2"/>
</xsl:template>
<xsl:template name="dvt_2">
<xsl:variable name="Rows" select="/ArrayOfPeriodAttendanceGroup/PeriodAttendanceGroup[ItemInfo/PeriodAttendanceInfo/ItemId=2075]"/>
<xsl:variable name="dvt_RowCount" select="count($Rows)"/>
<xsl:call-template name="dvt_2.rowContents">
<xsl:with-param name="Rows" select="$Rows"/>
</xsl:call-template>
</xsl:template>
<xsl:template name="dvt_2.rowContents">
<xsl:param name="Rows"/>
<xsl:for-each select="$Rows">
<xsl:sort select="ItemInfo/PeriodAttendanceInfo" order="ascending"/>
<xsl:call-template name="dvt_2.rowContentsView"/>
</xsl:for-each>
</xsl:template>
<xsl:template name="dvt_2.rowContentsView">
<xsl:variable name="subjectName" select="ItemInfo/PeriodAttendanceInfo/ItemText"/>
<tr class="{$subjectName}">
<xsl:element name="td">
<xsl:attribute name="class">
<xsl:value-of select="ItemInfo/PeriodAttendanceInfo/ItemText"/>
</xsl:attribute>
<xsl:variable name="subjectID" select="ItemInfo/PeriodAttendanceInfo/ItemId"/>
<a class="leftAlign" href="../Departments/{$subjectID}">
<xsl:value-of select="ItemInfo/PeriodAttendanceInfo/ItemText"/>
</a>
</xsl:element>
<td>
<p class="name">
<xsl:value-of select="Total"/>
</p>
</td>
<td>
<p class="name">
<xsl:value-of select="Present"/>
</p>
</td>
<td>
<p class="name">
<xsl:value-of select="Late"/>
</p>
</td>
<td>
<p class="name">
<xsl:value-of select="UnauthorisedAbsence"/>
</p>
</td>
</tr>
</xsl:template>
<xsl:template name="dvt_1.empty">
<xsl:variable name="dvt_ViewEmptyText">There is no timetable view for today</xsl:variable>
<table border="0" width="100%">
<tr>
<td class="ms-vb">
<xsl:value-of select="$dvt_ViewEmptyText"/>
</td>
</tr>
</table>
</xsl:template>
</xsl:stylesheet>