Can I use more than one selection criteria with apply-templates? - xslt-1.0

Here is a snippet of the XML file:
<?xml version="1.0" encoding="utf-8"?>
<AssignmentHistory Version="171804">
<W20170828>
<StudentItems>
<Item>
<Name Counsel="13" NextCounsel="0" Completed="1">Name 1</Name>
<Type>Bible Reading (Main)</Type>
<Description>Bible Reading</Description>
</Item>
<Item>
<Name Counsel="50" NextCounsel="0" Completed="1">Name 2</Name>
<Type>#1 Student (Main)</Type>
<Description>Initial Call</Description>
</Item>
<Item>
<Name>Name A</Name>
<Type>Assistant</Type>
<Description>Initial Call</Description>
</Item>
<Item>
<Name Counsel="50" NextCounsel="0" Completed="1">Name 3</Name>
<Type>#2 Student (Main)</Type>
<Description>Return Visit</Description>
</Item>
<Item>
<Name>Name B</Name>
<Type>Assistant</Type>
<Description>Return Visit</Description>
</Item>
<Item>
<Name Counsel="33" NextCounsel="0" Completed="1">Name 4</Name>
<Type>#3 Student (Main)</Type>
<Description>Bible Study</Description>
</Item>
<Item>
<Name>Name C</Name>
<Type>Assistant</Type>
<Description>Bible Study</Description>
</Item>
</StudentItems>
</W20170828>
</AssignmentHistory>
Here is the XSL script:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msa="http://www.publictalksoftware.co.uk/msa">
<xsl:output method="html" indent="yes" version="4.01"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
doctype-public="//W3C//DTD XHTML 1.0 Transitional//EN"/>
<xsl:variable name="PubDB" select="document('MSA_PublisherDatabase.XML')"/>
<xsl:variable name="History" select="document('AssignHistory.XML')"/>
<xsl:template match="/">
<html>
<head>
<title>Students - Full History Report</title>
<!--<link rel="stylesheet" type="text/css" href="Custom Publisher Report.css"/>-->
</head>
<body>
<table style="width: 100%; border: 1px solid #000000; border-collapse: collapse;">
<xsl:apply-templates select="$PubDB/msa:PublisherDatabase/msa:Publishers/msa:Publisher">
<xsl:sort select="msa:Name" data-type="text" order="ascending"/>
</xsl:apply-templates>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="msa:Publisher">
<tr>
<td colspan="5" style="border: 1px solid #000000">
<xsl:value-of select="msa:Name"/>
</td>
</tr>
<xsl:apply-templates select="$History/AssignmentHistory/*/StudentItems/Item[Name=current()/msa:Name]"/>
<tr>
<td colspan="5" style="border-top-style: solid; border-top-width: 1px; border-bottom-style: solid; border-bottom-width: 1px;">
<xsl:text> </xsl:text>
</td>
</tr>
</xsl:template>
<xsl:template match="Item">
<xsl:if test="position()=1">
<tr>
<td style="border: 1px solid #000000">
<xsl:text>Date</xsl:text>
</td>
<td style="border: 1px solid #000000">
<xsl:text>Item</xsl:text>
</td>
<td style="border: 1px solid #000000">
<xsl:text>Study Point</xsl:text>
</td>
<td style="border: 1px solid #000000">
<xsl:text>Next Study Point</xsl:text>
</td>
<td style="border: 1px solid #000000">
<xsl:text>Completed</xsl:text>
</td>
</tr>
</xsl:if>
<tr>
<td style="border: 1px solid #000000">
<xsl:value-of select="name(../..)"/>
</td>
<td style="border: 1px solid #000000">
<xsl:value-of select="Type"/>
</td>
<td style="border: 1px solid #000000">
<xsl:value-of select="Name/#Counsel"/>
</td>
<td style="border: 1px solid #000000">
<xsl:value-of select="Name/#NextCounsel"/>
</td>
<td style="border: 1px solid #000000">
<xsl:value-of select="Name/#Completed"/>
</td>
</tr>
</xsl:template>
</xsl:stylesheet>
It works fine. But I want to exclude from the results in the apply-templates call:
<xsl:apply-templates select="$History/AssignmentHistory/*/StudentItems/Item[Name=current()/msa:Name]"/>
... any Item that has a value of Assistant for the Type element.
Update
At the moment I have changed it to use a xsl:if clause but it would be more elegant for the apply-templates call to directly omit these elements where possible:
Date
Item
Study Point
Next Study Point
Completed
<xsl:if test="Type != 'Assistant'">
<tr>
<td class="CellNormal CellBorder">
<xsl:value-of select="name(../..)"/>
</td>
<td class="CellNormal CellBorder">
<xsl:value-of select="Type"/>
</td>
<td class="CellNormal CellBorder">
<xsl:value-of select="Name/#Counsel"/>
</td>
<td class="CellNormal CellBorder">
<xsl:value-of select="Name/#NextCounsel"/>
</td>
<td class="CellNormal CellBorder">
<xsl:value-of select="Name/#Completed"/>
</td>
</tr>
</xsl:if>

Related

Background color not working when converting file to HTML to PDF using FOP

I have try to generate PDF from HTML using FOP. My problem is background color in not working for Table. My html code is
<table cols="100 100pt" border="1" width="100%" align="center">
<thead>
<tr>
<th style="background-color: blue"><span style="color: blue">col 1</span></th>
<th style="background-color: #ffffff">col 2</th>
</thead>
<tbody>
<tr>
<td style="background-color: #ffffff">value 1</td>
<td>Value 2</td>
</tr>
</tbody>
</table>
and my xsl code is
<xsl:template match="table">
<fo:table table-layout="fixed">
<xsl:choose>
<xsl:when test="#cols">
<xsl:call-template name="build-columns">
<xsl:with-param name="cols"
select="concat(#cols, ' ')" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<fo:table-column column-width="200pt" />
</xsl:otherwise>
</xsl:choose>
<fo:table-body>
<xsl:apply-templates select="*" />
</fo:table-body>
</fo:table>
</xsl:template>
<xsl:template match="td">
<fo:table-cell>
<fo:block text-align="{$align}">
<xsl:apply-templates select="*|text()"/>
</fo:block>
</fo:table-cell>
</xsl:template>
Can any one know how to add back ground color for table in PDF?
IF the only property in #style is background-color and the values are as consistent in your example, then extract the color from #style if #style exists:
<xsl:template match="td">
<fo:table-cell>
<xsl:if test="#style">
<xsl:attribute name="background-color">
<xsl:value-of select="substring-after(#style, 'background-color: ')" />
</xsl:attribute>
</xsl:if>
...
This could be simpler if you were using XSLT 2.0 or XSLT 3.0.

XSL Display attribute after a certain character

I Have a Attribute that I want to display, but I only want to display the last portion of it indicated by an "-". I am using substring-after to do this but this only works if there is one charactor. There are occasions where there might be one and some where there is two. I have seen some recursive templates for this but I have not seen them in a For-each Loop like I have it here and I am not sure where I would put everything in my XSL document.
Here is my XML document:
<?xml version="1.0" encoding="UTF-8"?>
<JobList>
<Job T.number="28" />
<Job T.identifier="10mm Drill" />
<Job oper.jobName="2: T28-Contour Milling - Grind me back" />
<Job T.number="3" />
<Job T.identifier="9mm Drill" />
<Job oper.jobName="3: T3 Contour Milling" />
</JobList>
Here is my XSL Document. I am using XSL 1.0. The result I am looking for is I want this to be displayed as "10mm Drill - Grind me back" not "10mm Drill-Contour Milling - Grind me back" which is what I am getting now using the substring-after function or something with the same result.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" encoding="UTF-8" method="xml" />
<xsl:param name="REPORT">joblist</xsl:param>
<xsl:param name="LOCALE">en-GB</xsl:param>
<xsl:param name="FORMAT">html</xsl:param>
<xsl:template match="/">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>Tool Report</title>
</head>
<body>
<xsl:apply-templates />
</body>
</html>
</xsl:template>
<xsl:template match="JobList">
<div style="font-size:;">
<table width="100%" style="margin-bottom:50px;font:bold 10px arial;">
<thead>
<tr>
<th style="text-align:center;font-family:Arial;font-size:13;font:bold 7px arial;">
<xsl:value-of select="#month">
</xsl:value-of>
<span>.</span>
<xsl:value-of select="#day">
</xsl:value-of>
<span>.</span>
<xsl:value-of select="#year">
</xsl:value-of>
</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:center;font:normal 7px arial;font-size:12px;">
<xsl:value-of select="//Job[position()=1]/#cfg.JOBLISTNAME" />
<span>
</span>
<span>
</span>
</td>
</tr>
</tbody>
<table width="100%" border="1" style="margin-bottom:50px;font:13px arial;">
<thead style="font:19;">
<tr style="font-size:19;">
<td style="text-align:center;font-weight:bold;font-size:19;">
</td>
<td style="text-align:center;font-weight:bold;font-size:19;">
</td>
<td style="text-align:center;font-weight:bold;font-size:19;">
</td>
<td style="text-align:center;font-weight:bold;font-size:19;">
</td>
<td style="text-align:center;font-weight:bold;font-size:19;">
</td>
<td style="text-align:center;font-weight:bold;font-size:19;">
</td>
<td style="text-align:center;font-weight:bold;font-size:19;">
</td>
<td style="text-align:center;font-weight:bold;font-size:19;">
</td>
<td style="text-align:center;font-weight:bold;font-size:19;">
</td>
</tr>
</thead>
<tbody style="font-size:19;">
<xsl:for-each select="//Job[not(#T.number=preceding::Job/#T.number)]">
<tr style="font-size:19;">
<td style="font-size:19;">
<xsl:value-of select="#T.number" />
</td>
<td>
</td>
<td style="font-size:19;">
<xsl:value-of select="#T.identifier" />
<xsl:choose>
<xsl:when test="contains(#T.toolComment3, 'GRIND') or contains(#T.toolComment3, 'Grind')">
<xsl:value-of select="#T.toolComment3" />
</xsl:when>
</xsl:choose>
<xsl:choose>
<xsl:when test="contains(#T.comment2, 'GRIND') or contains(#T.comment2, 'Grind')">
<xsl:value-of select="#T.comment2" />
</xsl:when>
</xsl:choose>
<xsl:choose>
<xsl:when test="contains(#oper.jobName, 'GRIND') or contains(#oper.jobName, 'Grind')">
<xsl:value-of select="substring-after(#oper.jobName, '-')" />
</xsl:when>
</xsl:choose>
</td>
</tr>
</xsl:for-each>
</tbody>
</table>
</table>
</div>
</xsl:template>
</xsl:stylesheet>
Use a named recursive template to get the last token of the text string.
<xsl:template name="last-token">
<xsl:param name="text"/>
<xsl:param name="delimiter" select="'-'"/>
<xsl:choose>
<xsl:when test="contains($text, $delimiter)">
<!-- recursive call -->
<xsl:call-template name="last-token">
<xsl:with-param name="text" select="substring-after($text, $delimiter)"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
Example of call: http://xsltransform.net/bFWR5Ew

Grouping SQL elements with XSL

I've been working on a XSL style sheet for a specific SQL query table. I would like to group the results by 'tcode' and sum the values of each of the number columns. Any help would be appreciated.
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:strip-space elements="h_ind h_year h_code" />
<xsl:variable name="v_warning" select="CustomDeferredReport/title/ds_type" />
<xsl:template match="/">
<HTML>
<BODY>
<TABLE>
<TR valign="top">
<TD style="color:black; font-family: arial; font-size: 14pt; font-weight: bold" width="800">
<xsl:choose>
<xsl:when test="$v_warning = '1'">
<xsl:value-of select="CustomDeferredReport/title/rpt_title" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="CustomDeferredReport/title/rpt_warning" />
</xsl:otherwise>
</xsl:choose>
</TD>
</TR>
</TABLE>
<xsl:choose>
<xsl:when test="$v_warning = 1">
<TABLE>
<TR style="text-decoration: underline; font-family: arial; font-size: 8pt; font-weight: bold">
<BOLD>
<TD width="100">Code</TD>
<TD width="200">Name</TD>
<TD width="100">Beginning Balance</TD>
<TD width="100">Current Activity</TD>
<TD width="100">Other Activity</TD>
<TD width="100">Balance Sheet Only Activity</TD>
<TD width="100">Ending Balance</TD>
</BOLD>
</TR>
<xsl:for-each select='/CustomDeferredReport/temps'>
<TR style="font-family: arial; font-size: 8pt">
<TD><xsl:value-of select='tcode'/></TD>
<TD><xsl:value-of select='tname'/></TD>
<TD align="right"><xsl:value-of select='tbbal'/></TD>
<TD align="right"><xsl:value-of select='tdiff'/></TD>
<TD align="right"><xsl:value-of select='tothd'/></TD>
<TD align="right"><xsl:value-of select='tbsd'/></TD>
<TD align="right"><xsl:value-of select='tebal'/></TD>
</TR>
</xsl:for-each>
</TABLE>
</xsl:when>
<xsl:otherwise>
</xsl:otherwise>
</xsl:choose>
</BODY>
</HTML>
</xsl:template>
</xsl:stylesheet>
Here you go.
In XSLT there is a very common grouping technique you can use that involves a key and the generate-id() function, it is called muenchian grouping (Google it).
Anyhow, I added a key at the top of your solution called, key_t-code, and then use it several times in the solution. The trick here is when itterating over the for-each loop to only do something, in your case sum the nodes when you encounter the loop the first time, achieved by using the key and the generate-id. Enough said. An example is worth a thousand words. Here you go... oh, I did have to correct your XSLT n a couple of places. Mostly your context was off here and there.
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:strip-space elements="h_ind h_year h_code" />
<xsl:key name="key_t-code" match="temps" use="tcode"/>
<xsl:variable name="v_warning" select="/CustomDeferredReport/title/ds_type" />
<xsl:template match="/">
<HTML>
<BODY>
<TABLE>
<TR valign="top">
<TD style="color:black; font-family: arial; font-size: 14pt; font-weight: bold" width="800">
<xsl:choose>
<xsl:when test="$v_warning = '1'">
<xsl:value-of select="CustomDeferredReport/title/rpt_title" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="CustomDeferredReport/title/rpt_warning" />
</xsl:otherwise>
</xsl:choose>
</TD>
</TR>
</TABLE>
<xsl:choose>
<xsl:when test="$v_warning = 1">
<TABLE>
<TR style="text-decoration: underline; font-family: arial; font-size: 8pt; font-weight: bold">
<BOLD>
<TD width="100">Code</TD>
<TD width="200">Name</TD>
<TD width="100">Beginning Balance</TD>
<TD width="100">Current Activity</TD>
<TD width="100">Other Activity</TD>
<TD width="100">Balance Sheet Only Activity</TD>
<TD width="100">Ending Balance</TD>
</BOLD>
</TR>
<xsl:for-each select='CustomDeferredReport/temps'>
<xsl:if test="generate-id(key('key_t-code', tcode)[1]) = generate-id(.)">
<TR style="font-family: arial; font-size: 8pt">
<TD><xsl:value-of select='tcode'/></TD>
<TD><xsl:value-of select='tname'/></TD>
<TD align="right"><xsl:value-of select="sum(key('key_t-code', tcode)/tbbal)"/></TD>
<TD align="right"><xsl:value-of select="sum(key('key_t-code', tcode)/tdiff)"/></TD>
<TD align="right"><xsl:value-of select="sum(key('key_t-code', tcode)/tothd)"/></TD>
<TD align="right"><xsl:value-of select="sum(key('key_t-code', tcode)/tbsd)"/></TD>
<TD align="right"><xsl:value-of select="sum(key('key_t-code', tcode)/tebal)"/></TD>
</TR>
</xsl:if>
</xsl:for-each>
</TABLE>
</xsl:when>
<xsl:otherwise>
</xsl:otherwise>
</xsl:choose>
</BODY>
</HTML>
</xsl:template>
</xsl:stylesheet>
And the Xml
<?xml version="1.0" encoding="UTF-8"?>
<CustomDeferredReport>
<title>
<ds_type>1</ds_type>
<rpt_title>some title rpt_title</rpt_title>
<rpt_warning>some title rpt_warning</rpt_warning>
</title>
<temps>
<tcode>AAA</tcode>
<tname>Tripel A</tname>
<tbbal>9.99</tbbal>
<tdiff>.24</tdiff>
<tothd>23</tothd>
<tbsd>5.00</tbsd>
<tebal>62</tebal>
</temps>
<temps>
<tcode>AAA</tcode>
<tname>Tripel A</tname>
<tbbal>3.99</tbbal>
<tdiff>1.24</tdiff>
<tothd>2.03</tothd>
<tbsd>50.00</tbsd>
<tebal>63.23</tebal>
</temps>
<temps>
<tcode>AAA</tcode>
<tname>Tripel A</tname>
<tbbal>.99</tbbal>
<tdiff>24</tdiff>
<tothd>2.3</tothd>
<tbsd>500</tbsd>
<tebal>65.23</tebal>
</temps>
<temps>
<tcode>BB</tcode>
<tname>Double B</tname>
<tbbal>2</tbbal>
<tdiff>.24</tdiff>
<tothd>23</tothd>
<tbsd>5.00</tbsd>
<tebal>62</tebal>
</temps>
<temps>
<tcode>BB</tcode>
<tname>Double B</tname>
<tbbal>4</tbbal>
<tdiff>11.24</tdiff>
<tothd>28.03</tothd>
<tbsd>5.23</tbsd>
<tebal>.26</tebal>
</temps>
<temps>
<tcode>BB</tcode>
<tname>Double A</tname>
<tbbal>6</tbbal>
<tdiff>32</tdiff>
<tothd>223</tothd>
<tbsd>6.7</tbsd>
<tebal>12.23</tebal>
</temps>
</CustomDeferredReport>
To run this solution separate of your environment, so to see this run in a browser locally, just add the following deceleration just below the existing xml declaration in your Xml (and to be safe, use my Xml).
<?xml-stylesheet type='text/xsl' href='tcode.xsl'?>
Take the XSLT I have written and save it to disk and name it tcode.xsl. This transformation should work lickity split in IE but if you insist on running it in Chrome, well you have to set a flag that enables local files to run... --allow-file-access-from-files
After adding the xml-stylesheet deceleration to your Xml, drag the Xml into an IE browser and it should transform it.

Displaying tables based on multiple conditions in XSLT

I have five values that come from a form; like state1, state2, state3, state4, and state5.
Each value can be either 'New' or 'Closed'.
A Report will be displayed based on these values.
So, I created 5 tables, one each to be displayed on the report.
If a value is 'New' then display the respective table else no need to display.
So, I created XSLT like the below (this is just a fragment from my code).
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html" omit-xml-declaration="yes" standalone="yes" indent="yes"cdata-section-elements="script msxsl:script"></xsl:output>
<xsl:template match="/">
<html>
<head><title>Report</title></head>
<body>
<table class="row1">
<tr>
<td align="left" colspan="2">
<img src="../images/Logos/logo.gif" height="80"></img>
</td>
</tr>
</table>
<xsl:if test="(state1='New') and (state2='Closed') and (state3='Closed') and (state4='Closed') and (state5='Closed')">
<table class="row2">
<tr>
<td class="section" uniqueID="ms__id17">
<b>Details(S1)</b>
</td>
</tr>
<!--some rows -->
</table>
</xsl:if>
<xsl:if test="(state1='New') and (state2='New') and (state3='Closed') and (state4='Closed') and (state5='Closed')">
<table class="row2">
<tr>
<td class="section" uniqueID="ms__id18">
<b>Details(S1)</b>
</td>
</tr>
<!--some rows -->
</table>
<table class="row3">
<tr>
<td class="section" uniqueID="ms__id19">
<b>Details(S2)</b>
</td>
</tr>
<!--some rows -->
</table>
</xsl:if>
<!--more conditions-->
</body>
</html>
</xsl:template>
</xsl:stylesheet>
If I keep on giving conditions like this I should give 5! conditions.
Is there a better way of doing this.
Is this what you want (use or instead of and)?
<xsl:if test="(state1='New') or (state2='New') or (state3='New') or (state4='New') or (state5='New')">
<table class="row2">
<tr>
<td class="section" uniqueID="ms__id17">
<b>Details(S1)</b>
</td>
</tr>
<!--some rows -->
</table>
</xsl:if>

XSL xsl:when-test, prefix

I am workin on my HW xml/xsl. I am really new-bee in this area. Here is my code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:pre="/home/sbtge/Documents/1.SCHOOL/Webove_technologie/vypracovanie"
exclude-result-prefixes="pre">
<xsl:output method="html"/>
<xsl:template match="pre:document">
<html>
<link rel="stylesheet" href="nutri.css" type="text/css"/>
<head>
<title> Nutričné hodnoty </title>
</head>
<body>
<h1> Nutričné hodnoty </h1>
<div>
<table>
<tr>
<th>Name</th>
<th>Kategória <br/> (g) </th>
<th>Cukry <br/> (g) </th>
<th>Tuky <br/> (g) </th>
<th>Bielkoviny <br/> (g) </th>
<th>Energia <br/> (kJ) </th>
</tr>
<xsl:apply-templates select="pre:food"/>
</table>
</div>
</body>
</html>
</xsl:template>
<xsl:template match="pre:food">
<tr>
<td><xsl:value-of select="pre:name"/></td>
<xsl:choose>
<xsl:when test="pre:category='Zelenina'">
<div class="Zelenina">
<td><xsl:value-of select="pre:category"/></td>
</div>
</xsl:when>
<xsl:when test="pre:category='Ovocie'">
<div class="Ovocie">
<td><xsl:value-of select="pre:category"/></td>
</div>
</xsl:when>
<xsl:when test="pre:category='Ryža'">
<div class="Ryza">
<td><xsl:value-of select="pre:category"/></td>
</div>
</xsl:when>
<xsl:when test="pre:category='Mäso'">
<div class="Maso">
<td><xsl:value-of select="pre:category"/></td>
</div>
</xsl:when>
</xsl:choose>
<xsl:apply-templates select="pre:values"/>
</tr>
</xsl:template>
<xsl:template match="pre:values">
<td><xsl:value-of select="pre:sacharides"/> g</td>
<td><xsl:value-of select="pre:fat"/> g</td>
<td><xsl:value-of select="pre:proteins"/> g</td>
<td><xsl:value-of select="pre:energy"/> g</td>
</xsl:template>
everything works good but xsl:choose is ignored. I think it is because of bad "test" declaration. How should I correct it? Thanks a lot. I tried everything like: #pre:category, pre:#category, #category.
There were bad defined attributes in xml file. XSL should look like:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns= "/home/sbtge/Documents/1.SCHOOL/Webove_technologie/vypracovanie"
exclude-result-prefixes="ns">
<xsl:output method="html"/>
<xsl:template match="ns:document">
<html>
<link rel="stylesheet" href="nutri.css" type="text/css"/>
<head>
<title> Nutričné hodnoty </title>
</head>
<body>
<h1> Nutričné hodnoty </h1>
<div>
<table>
<tr>
<th>Name</th>
<th>Kategória <br/> (g) </th>
<th>Cukry <br/> (g) </th>
<th>Tuky <br/> (g) </th>
<th>Bielkoviny <br/> (g) </th>
<th>Energia <br/> (kJ) </th>
</tr>
<xsl:apply-templates select="ns:food"/>
</table>
</div>
</body>
</html>
</xsl:template>
<!-- <xsl:template match="document">
sdafsa
<xsl:apply-templates select="food"/>
</xsl:template> -->
<xsl:template match="ns:food">
<tr>
<td><xsl:value-of select="ns:name"/></td>
<xsl:choose>
<xsl:when test="#category='Zelenina'">
<div class="Zelenina">
<xsl:value-of select="#category"/>
</div>
</xsl:when>
<xsl:when test="#category='Ovocie'">
<div class="Ovocie">
<xsl:value-of select="#category"/>
</div>
</xsl:when>
<xsl:when test="#category='Ryža'">
<div class="Ryza">
<xsl:value-of select="#category"/> </div>
</xsl:when>
<xsl:when test="#category='Mäso'">
<div class="Maso">
<xsl:value-of select="#category"/>
</div>
</xsl:when>
</xsl:choose>
<xsl:apply-templates select="ns:values"/>
</tr>
</xsl:template>
<xsl:template match="ns:values">
<td><xsl:value-of select="ns:sacharides"/> g</td>
<td><xsl:value-of select="ns:fat"/> g</td>
<td><xsl:value-of select="ns:proteins"/> g</td>
<td><xsl:value-of select="ns:energy"/> Kj</td>
</xsl:template>
Everyone should help himself :D