Fetching the correct value of IH_TITLE from csv file and inject in span element - xslt-1.0

Need to inject title in span element from csv file matching id attribute of span element with IH_No in csv file. Once HTML span element id attribute matches with IH_No in csv file then corresponding IH_Title value in csv should be injected in span element
I have got the partial solution it just that I am not able to fetch just the IH_TITLE value in span element instead the whole row is getting fetched.
Note: This is just chunk of the original csv file moreover the numbers will be 100K approx, So need a solution without having to use multiple conditions for IH_NO in csv.
The below XSl is working partially, when input the input has just IH_NO and IH_TITLE, However its is not working if it has multiple columns in csv file.
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:strip-space elements="*"/>
<xsl:key name="title" match="IH_TITLE" use="#IH_NO" />
<xsl:variable name="titles">
<xsl:for-each select="tokenize(unparsed-text('test.csv'), '\n')">
<IH_TITLE IH_NO="{translate(substring-before(., ';'), '"', '')}">
<xsl:value-of select="tokenize(., ';')[2]" />
<xsl:value-of select="substring-before(
substring-after ( substring-after (., ';'), ';')
, ';')"/>
</IH_TITLE>
</xsl:for-each>
</xsl:variable>
<!-- identity transform -->
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="#*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="span[#class='ih']">
<xsl:copy>
<xsl:copy-of select="#*"/>
<xsl:value-of select="key('title', substring-after(#id, 'ih-'), $titles)" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Current HTML structure
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
</head>
<body>
<div class="chapter">
<h1 class="title">
<span class="ih" id="ih-8000003034"></span>
</h1>
</div>
<div class="chapter">
<h1 class="title">
<span class="ih" id="ih-8000003052"></span>
</h1>
</div>
<div class="chapter">
<h1 class="title">
<span class="ih" id="ih-8000003058"></span>
</h1>
</div>
</body>
</html>
Expected HTML structure
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
</head>
<body>
<div class="chapter">
<h1 class="title">
<span class="ih" id="ih-8000003034">replace Hydraulic pump, replace</span>
</h1>
</div>
<div class="chapter">
<h1 class="title">
<span class="ih" id="ih-8000003052">replace;Hydraulic pump, replace</span>
</h1>
</div>
<div class="chapter">
<h1 class="title">
<span class="ih" id="ih-8000003058">replace;Hydraulic pump, replace</span>
</h1>
</div>
</body>
</html>
Filename for csv is test.csv, Need to import this csv file in xsl and match the values with span element and fetch the IH_Title values in span element.
"IH_NO";"OP_NO";"IH_TITLE";"OP_ID"
"8000003034";"26202-2";replace;Coolant pump, replace;"26202"
"8000003052";"26202-3";replace;Fuel pump, replace;"26203"
"8000003058";"26202-4";replace;Hydraulic pump, replace;"26204"

Change the definition of the titles variable to:
<xsl:variable name="titles">
<xsl:for-each select="tokenize(unparsed-text('test.csv'), '\n')">
<xsl:variable name="cells" select="tokenize(., ';')" />
<IH_TITLE IH_NO="{translate($cells[1], '"', '')}">
<xsl:value-of select="$cells[3], $cells[4]" separator=";"/>
</IH_TITLE>
</xsl:for-each>
</xsl:variable>

Related

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

xslt 1.0 how to create differentes variable inside foreach loop

i have xml source as result of sql query and i show all on browser with xsl file. Inside a for each loop i need to create dinamically a different variable for each iteration because of i have to pass this variable to javascript function to be elaborated and the result push html on a tag with ID. I don't know how to assign a correct name to the variable. I wrote this that doesn't work:
<xsl:for-each select="Record">
<table id="tableId-{position()}">
<thead>
<tr>
<th>Testata 1</th>
<th>Testata 2</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<xsl:variable name="variableN">
<xsl:call-template name="string-replace-all">
<xsl:with-param name="text" select="testo" />
<xsl:with-param name="replace">'</xsl:with-param>
<xsl:with-param name="by">\'</xsl:with-param>
</xsl:call-template>
</xsl:variable>
<script>
displayTableRowsDueColById('<xsl:value-of select="$variableN" />');
</script>
</xsl:if>
</xsl:for-each>
One thing you could do is create a template that contains the variable and the call to your javascript function. Pass in whatever you need for the string-replace-all. Then call the template within the script tags as follows:
(Sample code not tested.)
<xsl:for-each select="Record">
<table id="tableId-{position()}">
<thead>
<tr>
<th>Testata 1</th>
<th>Testata 2</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<script>
<xsl:call-template name="callDisplayTable">
<xsl:with-param name="text" select=" <Put some value here> "/>
</xsl:call-template>
</script>
</xsl:if>
</xsl:for-each>
<xsl:template name="callDisplayTable">
<xsl:param name="text"/>
<xsl:variable name="variableN">
<xsl:call-template name="string-replace-all">
<xsl:with-param name="text" select="$text" />
<xsl:with-param name="replace">'</xsl:with-param>
<xsl:with-param name="by">\'</xsl:with-param>
</xsl:call-template>
</xsl:variable>
displayTableRowsDueColById('<xsl:value-of select="$variableN" />');
</xsl:template>

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.

transform oracle's xml to html using xslt?

I need to transform xml (to html using xslt) file which I made by downloading a dataset from oracle sqldeveloper HR schema! Please help me to write xsl file which will transform the downloaded data into a table!
Piece of xml
<?xml version='1.0' encoding='UTF8'?>
<RESULTS>
<ROW>
<COLUMN NAME="Employee_Names"><![CDATA[Steven]]></COLUMN>
<COLUMN NAME="Salary"><![CDATA[24000]]></COLUMN>
<COLUMN NAME="STREET_ADDRESS"><![CDATA[1297 Via Cola di Rie]]></COLUMN>
</ROW>
<ROW>
<COLUMN NAME="Employee_Names"><![CDATA[Neena]]></COLUMN>
<COLUMN NAME="Salary"><![CDATA[17000]]></COLUMN>
<COLUMN NAME="STREET_ADDRESS"><![CDATA[1297 Via Cola di Rie]]></COLUMN>
</ROW>
All my data displays in strings not table( please help
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"/>
<xsl:template match="/RESULTS">
<html>
<head>
<title>Table data</title>
</head>
<body>
<table>
<thead>
<!-- Extract the column-names from the first row. -->
<xsl:apply-templates select="ROW[1]" mode="header"/>
</thead>
<tbody>
<xsl:apply-templates select="ROW"/>
</tbody>
</table>
</body>
</html>
</xsl:template>
<!-- "header"-mode generates the column headers. -->
<xsl:template match="ROW" mode="header">
<tr>
<xsl:apply-templates match="COLUMN" mode="header"/>
</tr>
</xsl:template>
<xsl:template match="COLUMN" mode="header">
<th>
<xsl:value-of select="#NAME"/>
</th>
</xsl:template>
<!-- normal mode generates the table data -->
<xsl:template match="ROW">
<tr>
<xsl:apply-templates match="COLUMN"/>
</tr>
</xsl:template>
<xsl:template match="COLUMN">
<td>
<xsl:value-of select="text()"/>
</td>
</xsl:template>
</xsl:stylesheet>
Output:
<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1- transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Table data</title>
</head>
<body>
<table>
<thead>
<tr>
<th>Employee_Names</th>
<th>Salary</th>
<th>STREET_ADDRESS</th>
</tr>
</thead>
<tbody>
<tr>
<td>Steven</td>
<td>24000</td>
<td>1297 Via Cola di Rie</td>
</tr>
<tr>
<td>Neena</td>
<td>17000</td>
<td>1297 Via Cola di Rie</td>
</tr>
</tbody>
</table>
</body>
</html>

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