In below Code I have xml input which shows booktypes.I want to arrange book types according to there types in each columns. Some columns have values some not. Check expected output.
Input
<?xml version="1.0" encoding="UTF-8"?>
<BookTypes>
<Types>
<string>T1</string>
<string>T3,M1,P1</string>
<string>T2,P2</string>
<string>M3,P3</string>
</Types>
</BookTypes>
XSLT script: Current xslt script gives me result but not as expected.
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:exsl="http://exslt.org/common"
extension-element-prefixes="exsl">
<xsl:output method="xml" omit-xml-declaration="yes" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:variable name="types">
<type>T</type>
<type>M</type>
<type>P</type>
</xsl:variable>
<xsl:variable name="types-set" select="exsl:node-set($types)" />
<xsl:template match="/">
<table>
<tr>
<th>T Type</th>
<th>M Type</th>
<th>P Type</th>
</tr>
<xsl:for-each select="BookTypes/Types/string">
<tr>
<xsl:variable name="splitValue">
<xsl:apply-templates/>
</xsl:variable>
<xsl:for-each select="exsl:node-set($splitValue)/*">
<xsl:variable name="mySplittedValue" select="." />
<xsl:for-each select="$types-set/type">
<xsl:variable name="my-types" select="." />
<td>
<xsl:choose>
<xsl:when test="contains($mySplittedValue, $my-types)">
<xsl:value-of select="$mySplittedValue"/>
</xsl:when>
<xsl:otherwise>
<xsl:text>-</xsl:text>
</xsl:otherwise>
</xsl:choose>
</td>
</xsl:for-each>
</xsl:for-each>
</tr>
</xsl:for-each>
</table>
</xsl:template>
<xsl:template match="text()" name="split">
<xsl:param name="pText" select="."/>
<xsl:if test="string-length($pText) > 0">
<item>
<xsl:value-of select="substring-before(concat($pText, ','), ',')"/>
</item>
<xsl:call-template name="split">
<xsl:with-param name="pText" select="substring-after($pText, ',')"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
Expected output
<table>
<tr>
<th>T Type</th>
<th>M Type</th>
<th>P Type</th>
</tr>
<tr>
<td>T1</td>
<td>-</td>
<td>-</td>
</tr>
<tr>
<td>T3</td>
<td>M1</td>
<td>P1</td>
</tr>
<tr>
<td>T2</td>
<td>-</td>
<td>P2</td>
</tr>
<tr>
<td>-</td>
<td>M3</td>
<td>P3</td>
</tr>
</table>
Summery: Output
There are three(3) fixed types, P, M, T which are exist in any one input say P3, M3. here P3 contains P (type) so value P3 should come under column name P type. In input there are 3 or 2 or 1 value separed by , comma (say T3,M1,P1). That every value should be split first and then later display in table
I think you are making this more complicated that it needs to be. Try:
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:exsl="http://exslt.org/common"
extension-element-prefixes="exsl">
<xsl:output method="xml" omit-xml-declaration="yes" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:variable name="types">
<type>T</type>
<type>M</type>
<type>P</type>
</xsl:variable>
<xsl:variable name="types-set" select="exsl:node-set($types)" />
<xsl:template match="/">
<table>>
<tr>
<xsl:for-each select="$types-set/type">
<th><xsl:value-of select="concat(., ' Type')"/></th>
</xsl:for-each>
</tr>
<xsl:for-each select="BookTypes/Types/string">
<xsl:variable name="my-types" select="." />
<tr>
<xsl:for-each select="$types-set/type">
<td>
<xsl:choose>
<xsl:when test="contains($my-types, .)">
<xsl:value-of select="."/>
</xsl:when>
<xsl:otherwise>
<xsl:text>-</xsl:text>
</xsl:otherwise>
</xsl:choose>
</td>
</xsl:for-each>
</tr>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>
Result:
<table>
<tr>
<th>T Type</th>
<th>M Type</th>
<th>P Type</th>
</tr>
<tr>
<td>T</td>
<td>-</td>
<td>-</td>
</tr>
<tr>
<td>T</td>
<td>M</td>
<td>P</td>
</tr>
<tr>
<td>T</td>
<td>-</td>
<td>P</td>
</tr>
<tr>
<td>-</td>
<td>M</td>
<td>P</td>
</tr>
</table>
Related
i got the following XML Data and need to create 2 Tables looking like this with only xsl 1.0
Ribbon Rezept
Medikament
Dosis
08:00
12:00
18:00
22:00
ASPIRIN
0-0-0-1
0
0
0
1
Ribbon Medikarte
Medikament
Dosis
08:00
12:00
16:00
20:00
22:00
ASPIRIN
0-0-0-1
0
0
0
1
PONSTAN
1-0-0-1
1
0
0
1
But the result with the below xsl ist not creating the expected tables
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl"?>
<DATA>
<RIBBON_REZEPT>
<SRO_INT_REZEPT_INFO>
<MRO_INT_REZEPT>
<MEDIKAMENT_M CR="1">ASPIRIN</MEDIKAMENT_M>
<DOSIS_M CR="1">0-0-0-1</DOSIS_M>
<EINZELDOSIS>
<DOSIS_N>0</DOSIS_N>
<ZEIT_T>08:00</ZEIT_T>
</EINZELDOSIS>
<EINZELDOSIS>
<DOSIS_N>0</DOSIS_N>
<ZEIT_T>12:00</ZEIT_T>
</EINZELDOSIS>
<EINZELDOSIS>
<DOSIS_N>0</DOSIS_N>
<ZEIT_T>18:00</ZEIT_T>
</EINZELDOSIS>
<EINZELDOSIS>
<DOSIS_N>1</DOSIS_N>
<ZEIT_T>22:00</ZEIT_T>
</EINZELDOSIS>
<EINHEIT_M CR="1">Stk</EINHEIT_M>
</MRO_INT_REZEPT>
</SRO_INT_REZEPT_INFO>
</RIBBON_REZEPT>
<RIBBON_MEDIKARTE>
<SRO_INT_REZEPT_INFO>
<MRO_INT_REZEPT>
<MEDIKAMENT_M CR="1">ASPIRIN</MEDIKAMENT_M>
<DOSIS_M CR="1">0-0-0-1</DOSIS_M>
<EINZELDOSIS>
<DOSIS_N>0</DOSIS_N>
<ZEIT_T>08:00</ZEIT_T>
</EINZELDOSIS>
<EINZELDOSIS>
<DOSIS_N>0</DOSIS_N>
<ZEIT_T>12:00</ZEIT_T>
</EINZELDOSIS>
<EINZELDOSIS>
<DOSIS_N>0</DOSIS_N>
<ZEIT_T>16:00</ZEIT_T>
</EINZELDOSIS>
<EINZELDOSIS>
<DOSIS_N>1</DOSIS_N>
<ZEIT_T>20:00</ZEIT_T>
</EINZELDOSIS>
<EINHEIT_M CR="1">Stk</EINHEIT_M>
</MRO_INT_REZEPT>
<MRO_INT_REZEPT>
<MEDIKAMENT_M CR="1">PONSTAN</MEDIKAMENT_M>
<DOSIS_M CR="1">1-0-0-1</DOSIS_M>
<EINZELDOSIS>
<DOSIS_N>1</DOSIS_N>
<ZEIT_T>08:00</ZEIT_T>
</EINZELDOSIS>
<EINZELDOSIS>
<DOSIS_N>0</DOSIS_N>
<ZEIT_T>12:00</ZEIT_T>
</EINZELDOSIS>
<EINZELDOSIS>
<DOSIS_N>0</DOSIS_N>
<ZEIT_T>16:00</ZEIT_T>
</EINZELDOSIS>
<EINZELDOSIS>
<DOSIS_N>1</DOSIS_N>
<ZEIT_T>22:00</ZEIT_T>
</EINZELDOSIS>
<EINHEIT_M CR="1">Stk</EINHEIT_M>
</MRO_INT_REZEPT>
</SRO_INT_REZEPT_INFO>
</RIBBON_MEDIKARTE>
</DATA>
From this Post i got a Solution, but as the Times are different within the Sub-Nodes (Ribbon Rezept and Medikarte), it does not work as expected :(
<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ext="http://exslt.org/common" version="1.0">
<xsl:output encoding="ISO-8859-1" indent="yes" method="html"/>
<xsl:key match="EINZELDOSIS" name="data-by-time" use="ZEIT_T"/>
<xsl:key match="EINZELDOSIS" name="data-by-cell" use="concat(ZEIT_T, '|', generate-id(..))"/>
<xsl:template match="/">
<html>
<head charset="ISO-8859-1">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Medilist v2</title>
</head>
<body>
<p>Ribbon Rezept</p>
<xsl:call-template name="RIBBON">
<xsl:with-param name="medinode" select="/DATA/RIBBON_REZEPT/SRO_INT_REZEPT_INFO"/>
</xsl:call-template>
<p>Ribbon Medikarte</p>
<xsl:call-template name="RIBBON">
<xsl:with-param name="medinode" select="/DATA/RIBBON_MEDIKARTE/SRO_INT_REZEPT_INFO"/>
</xsl:call-template>
</body>
</html>
</xsl:template>
<xsl:template name="RIBBON">
<xsl:param name="medinode" />
<xsl:variable name="distinct-times-RTF">
<xsl:for-each select="$medinode/MRO_INT_REZEPT/EINZELDOSIS[count(. | key('data-by-time', ZEIT_T)[1]) = 1]">
<xsl:sort data-type="text" order="ascending" select="ZEIT_T"/>
<xsl:copy-of select="ZEIT_T"/>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="distinct-times" select="ext:node-set($distinct-times-RTF)/ZEIT_T"/>
<xsl:variable name="source_document" select="/"/>
<table border="1">
<thead>
<tr>
<th>Medi</th>
<th>Dosis</th>
<!-- a column header for each distinct time point -->
<xsl:for-each select="$distinct-times">
<th>
<xsl:value-of select="."/>
</th>
</xsl:for-each>
</tr>
</thead>
<tbody>
<xsl:for-each select="$medinode/MRO_INT_REZEPT">
<xsl:variable name="row-id" select="generate-id()"/>
<tr>
<td>
<xsl:value-of select="MEDIKAMENT_M"/>
</td>
<td>
<xsl:value-of select="DOSIS_M"/>
</td>
<!-- create a cell for each distinct time point
-->
<xsl:for-each select="$distinct-times">
<xsl:variable name="zeit" select="."/>
<td>
<!-- get matching data point -->
<!-- switch the context back to the source document -->
<xsl:for-each select="$source_document">
<xsl:value-of select="key('data-by-cell', concat($zeit, '|', $row-id))/DOSIS_N"/>
</xsl:for-each>
</td>
</xsl:for-each>
</tr>
</xsl:for-each>
</tbody>
</table>
</xsl:template>
</xsl:stylesheet>
i've put it as an example here on fiddle
Your XML has two branches - RIBBON_REZEPT and RIBBON_MEDIKARTE - with identical structure, apart from the name. In order to limit the first key to the current branch, you need to add the ID or the name of the branch to its value.
Instead of:
<xsl:key match="EINZELDOSIS" name="data-by-time" use="ZEIT_T"/>
define the key as:
<xsl:key match="EINZELDOSIS" name="data-by-time" use="concat(ZEIT_T, '|', name(../../..))" />
then call it as:
key('data-by-time', concat(ZEIT_T, '|', name($branch))
where $branch is either RIBBON_REZEPT or RIBBON_MEDIKARTE.
The other key is already limited to the current MRO_INT_REZEPT, so it can stay as it is.
With some streamlining, your stylesheet could look like this:
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:exsl="http://exslt.org/common"
extension-element-prefixes="exsl">
<xsl:output method="html"/>
<xsl:key name="data-by-time" match="EINZELDOSIS" use="concat(ZEIT_T, '|', name(../../..))" />
<xsl:key name="data-by-cell" match="EINZELDOSIS" use="concat(ZEIT_T, '|', generate-id(..))" />
<xsl:variable name="source_document" select="/" />
<xsl:template match="/DATA">
<html>
<body>
<p>Ribbon Rezept</p>
<xsl:call-template name="create-table">
<xsl:with-param name="branch" select="RIBBON_REZEPT"/>
</xsl:call-template>
<p>Ribbon Medikarte</p>
<xsl:call-template name="create-table">
<xsl:with-param name="branch" select="RIBBON_MEDIKARTE"/>
</xsl:call-template>
</body>
</html>
</xsl:template>
<xsl:template name="create-table">
<xsl:param name="branch"/>
<xsl:variable name="recepts" select="$branch/SRO_INT_REZEPT_INFO/MRO_INT_REZEPT"/>
<xsl:variable name="doses" select="$recepts/EINZELDOSIS"/>
<!-- distinct times -->
<xsl:variable name="distinct-times-RTF">
<xsl:for-each select="$doses[count(. | key('data-by-time', concat(ZEIT_T, '|', name($branch)))[1]) = 1]">
<xsl:sort select="ZEIT_T" data-type="text" order="ascending"/>
<xsl:copy-of select="ZEIT_T"/>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="distinct-times" select="exsl:node-set($distinct-times-RTF)/ZEIT_T" />
<!-- table -->
<table border="1">
<thead>
<tr>
<th>Medikament</th>
<th>Dosis</th>
<!-- a column header for each distinct time -->
<xsl:for-each select="$distinct-times">
<th>
<xsl:value-of select="."/>
</th>
</xsl:for-each>
</tr>
</thead>
<tbody>
<xsl:for-each select="$recepts">
<xsl:variable name="recept-id" select="generate-id()" />
<tr>
<td>
<xsl:value-of select="MEDIKAMENT_M"/>
</td>
<td>
<xsl:value-of select="DOSIS_M"/>
</td>
<!-- create a cell for each distinct time -->
<xsl:for-each select="$distinct-times">
<xsl:variable name="time" select="." />
<td>
<!-- switch the context back to the source document -->
<xsl:for-each select="$source_document">
<!-- get data from the intersection of column (time) and row (recept) -->
<xsl:value-of select="key('data-by-cell', concat($time, '|', $recept-id))/DOSIS_N" />
</xsl:for-each>
</td>
</xsl:for-each>
</tr>
</xsl:for-each>
</tbody>
</table>
</xsl:template>
</xsl:stylesheet>
I am trying to make xslt script which display result in tabular format but I am getting result column value added in next row. please check image below for expected output.
Input xml file:
<?xml version="1.0"?>
<Softwares>
<SubNodes>
<Software>
<Results>
<Info>
<Name>Visual Studio</Name>
<Key>Name</Key>
<Value>2010</Value>
</Info>
<Info>
<Name>Visual Studio</Name>
<Key>Driver ID</Key>
<Value>DI8745</Value>
</Info>
</Results>
</Software>
<Software>
<Results>
<Info>
<Name>Oracle</Name>
<Key>Name</Key>
<Value>Oracle8</Value>
</Info>
<Info>
<Name>Oracle</Name>
<Key>Driver ID</Key>
<Value>ID2345</Value>
</Info>
</Results>
</Software>
<Software>
<Results>
<Info>
<Name>SQL</Name>
<Key>Name</Key>
<Value>SQL2005</Value>
</Info>
<Info>
<Name>SQL</Name>
<Key>Driver ID</Key>
<Value>ID8888</Value>
</Info>
</Results>
</Software>
</SubNodes>
</Softwares>
XSLT file:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:w3="http://www.w3.org"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xsl:output method="html" indent="yes"/>
<xsl:template match="/">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body>
<table>
<tr>
<td>Name</td>
<td>Driver ID</td>
</tr>
<xsl:for-each select="//SubNodes/Software/Results/Info">
<tr>
<td>
<xsl:choose>
<xsl:when test="Key = 'Name'">
<xsl:value-of select="Value" />
</xsl:when>
</xsl:choose>
</td>
<td>
<xsl:choose>
<xsl:when test="Key = 'Driver ID'">
<xsl:value-of select="Value" />
</xsl:when>
</xsl:choose>
</td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Current Output:
Image shows current output which is not giving result in row by row.
Expected output
Image shows expected output which is giving result in row by row.
Your XSLT will output a row for every Info. Try this instead:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:w3="http://www.w3.org"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xsl:output method="html" indent="yes"/>
<xsl:template match="/">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body>
<table>
<tr>
<td>Name</td>
<td>Driver ID</td>
</tr>
<xsl:for-each select="//SubNodes/Software/Results">
<tr>
<td>
<xsl:choose>
<xsl:when test="Info[1]/Key = 'Name'">
<xsl:value-of select="Info[1]/Value" />
</xsl:when>
</xsl:choose>
</td>
<td>
<xsl:choose>
<xsl:when test="Info[2]/Key = 'Driver ID'">
<xsl:value-of select="Info[2]/Value" />
</xsl:when>
</xsl:choose>
</td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
When I try to transform this XAML document
<Section xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xml:space="preserve" TextAlignment="Left" LineHeight="Auto" IsHyphenationEnabled="False" xml:lang="en-us" FlowDirection="LeftToRight" NumberSubstitution.CultureSource="User" NumberSubstitution.Substitution="AsCulture" FontFamily="Arial" FontStyle="Normal" FontWeight="Normal" FontStretch="Normal" FontSize="12" Foreground="#FF000000" Typography.StandardLigatures="True" Typography.ContextualLigatures="True" Typography.DiscretionaryLigatures="False" Typography.HistoricalLigatures="False" Typography.AnnotationAlternates="0" Typography.ContextualAlternates="True" Typography.HistoricalForms="False" Typography.Kerning="True" Typography.CapitalSpacing="False" Typography.CaseSensitiveForms="False" Typography.StylisticSet1="False" Typography.StylisticSet2="False" Typography.StylisticSet3="False" Typography.StylisticSet4="False" Typography.StylisticSet5="False" Typography.StylisticSet6="False" Typography.StylisticSet7="False" Typography.StylisticSet8="False" Typography.StylisticSet9="False" Typography.StylisticSet10="False" Typography.StylisticSet11="False" Typography.StylisticSet12="False" Typography.StylisticSet13="False" Typography.StylisticSet14="False" Typography.StylisticSet15="False" Typography.StylisticSet16="False" Typography.StylisticSet17="False" Typography.StylisticSet18="False" Typography.StylisticSet19="False" Typography.StylisticSet20="False" Typography.Fraction="Normal" Typography.SlashedZero="False" Typography.MathematicalGreek="False" Typography.EastAsianExpertForms="False" Typography.Variants="Normal" Typography.Capitals="Normal" Typography.NumeralStyle="Normal" Typography.NumeralAlignment="Normal" Typography.EastAsianWidths="Normal" Typography.EastAsianLanguage="Normal" Typography.StandardSwashes="0" Typography.ContextualSwashes="0" Typography.StylisticAlternates="0">
<Table CellSpacing="1" Margin="0,0,0,0"><Table.Columns><TableColumn Width="264" /></Table.Columns><TableRowGroup><TableRow><TableCell Padding="0,0,0,0">
<Paragraph FontFamily="Times New Roman" FontSize="10.666666666666666" Margin="0,0,0,0">
<Span FontWeight="Bold"><Run>some text</Run></Span><Run> </Run>
<Span Foreground="#FF00681C"><Run>some more text</Run></Span>
</Paragraph>
</TableCell></TableRow></TableRowGroup></Table>
</Section>
using this XSL
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output omit-xml-declaration="yes" indent="yes" />
<xsl:strip-space elements="*" />
<xsl:output method="html"/>
<xsl:template match="/">
<html>
<body>
<xsl:apply-templates select="/Table"/>
<xsl:apply-templates select="/Paragraph"/>
<xsl:apply-templates select="/Run"/>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="Table">
<table>
<xsl:apply-templates select="TableRowGroup"/>
</table>
</xsl:template>
<xsl:template match="TableRowGroup">
<xsl:apply-templates select="TableRow"/>
</xsl:template>
<xsl:template match="TableRow">
<tr>
<xsl:apply-templates select="TableCell"/>
</tr>
</xsl:template>
<xsl:template match="TableCell">
<td>
</td>
</xsl:template>
<xsl:template match="Paragraph">
<p>
<xsl:apply-templates select=""/>
<xsl:apply-templates/>
</p>
</xsl:template>
<xsl:template match="Run">
<span>
<xsl:apply-templates/>
</span>
</xsl:template>
<xsl:template match="Span">
<span>
<xsl:apply-templates/>
</span>
</xsl:template>
</xsl:stylesheet>
i get this incorrect result
<html>
<body>
some text some more text
</body>
I saw a few problems with your XSLT that would stop it working.
There is no namespace in the XSLT. There needs to be a namespace that
matches the one in the input XML, and you need to use this namespace
when matching elements.
Your first template matches "/", which matches the root node. I
assume you actually want to match the document element Section. The
apply-templates inside this are matching elements beginning with
"/", which makes them absolute paths, so they won't match anything.
I've taken a guess at what output XML you expect. The following XSLT stylesheet:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
version="1.0"
exclude-result-prefixes="ns">
<xsl:strip-space elements="*" />
<xsl:output indent="yes" method="html"/>
<xsl:template match="/ns:Section">
<html>
<body>
<xsl:apply-templates select="ns:Table"/>
</body>
</html>
</xsl:template>
<xsl:template match="ns:Table">
<table>
<xsl:apply-templates select="ns:TableRowGroup"/>
</table>
</xsl:template>
<xsl:template match="ns:TableRowGroup">
<xsl:apply-templates select="ns:TableRow"/>
</xsl:template>
<xsl:template match="ns:TableRow">
<tr>
<xsl:apply-templates select="ns:TableCell"/>
</tr>
</xsl:template>
<xsl:template match="ns:TableCell">
<td>
<xsl:apply-templates select="ns:Paragraph"/>
</td>
</xsl:template>
<xsl:template match="ns:Paragraph">
<p>
<xsl:apply-templates select="ns:Span"/>
</p>
</xsl:template>
<xsl:template match="ns:Run">
<span>
<xsl:apply-templates/>
</span>
</xsl:template>
<xsl:template match="ns:Span">
<span>
<xsl:apply-templates select="ns:Run"/>
</span>
</xsl:template>
</xsl:stylesheet>
produces the following output when applied to your example input XML:
<html>
<body>
<table>
<tr>
<td>
<p><span><span>some text</span></span><span><span>some more text</span></span></p>
</td>
</tr>
</table>
</body>
</html>
which may need a little formatting...
Hi I have a part of my xml document as below. In this xsm document I have a special character as “ and ”. I want them to be replaced by “ and ” in my HTML output using XSL.
I am searching for a template or any other alternative method to scan my entire XML document and replace where ever the special characters are found. Right now it is being replaced by some white boxes. Please let me know how do I do it.
<para>
<phrase>2.081</phrase> In creating a vehicle like a restricted purpose company, the British Virgin Islands legislature was clearly concerned that, if such vehicles became widely used, there might be a risk that persons dealing with British Virgin Islands companies generally may have become concerned about the ability of companies to engage in day-to-day transactions. Accordingly, it sought to address these concerns by two slightly different mechanisms. Firstly, all restricted purpose companies were required to include the designation “(SPV) Limited” in their name, to make sure they were readily identifiable (even without reviewing their constitutional documents). Secondly, restricted purpose companies were made subject to licence fees significantly higher than regular companies to limit their use to appropriate cases.</para>
<table frame="all" width="100%">
<title>Comparing restricted purpose companies</title>
<tgroup cols="3">
<colspec colnum="1" colname="col1" colwidth="33%"/>
<colspec colnum="2" colname="col2" colwidth="33%"/>
<colspec colnum="3" colname="col3" colwidth="33%"/>
<thead>
I also want a method to get the number of <colspec> elements below <tgroup cols=""> (attribute cols should be there). There are also <tgroup> elements without the cols attribute.
This is my current 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:variable name="ThisDocument" select="document('')"/>
<xsl:template match="/">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>
<xsl:value-of select="chapter/title"/>
</title>
<link rel="stylesheet" href="er:#css" type="text/css" />
</head>
<body>
<xsl:apply-templates/>
<hr />
<section class="tr_footnotes">
<xsl:apply-templates select="//footnote" mode="footnote"/>
</section>
</body>
</html>
</xsl:template>
<xsl:template match="chapter">
<section>
<div class="chapter">
<a name="BVI-CH-{#num}" />
<xsl:variable name="cnum">
<xsl:choose>
<xsl:when test="starts-with(#num,'0')">
<xsl:value-of select="substring-after(#num,'0')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="#num"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable><div class="chapter-title"><span class="chapter-num">
<xsl:value-of select="concat('Chapter ',$cnum,' ')"/>
</span>
<xsl:apply-templates/>
</div></div>
</section>
</xsl:template>
<xsl:template match="chapter/para">
<div class="para align-right">
<span class="format-smallcaps">Para</span>.
</div>
</xsl:template>
<!-- Index templates -->
<xsl:template name="toc" match="chapter/toc">
<div class="toc">
<xsl:call-template name="toc-part"></xsl:call-template>
</div>
</xsl:template>
<xsl:template name="toc-part" match="chapter/toc/toc-part">
<div class="toc-part">
<xsl:call-template name="toc-div"></xsl:call-template>
</div>
</xsl:template>
<xsl:template name="toc-div" match="chapter/toc/toc-part/toc-div">
<table class="toc-div">
<tbody>
<xsl:for-each select="current()/toc-part/toc-div/*">
<xsl:call-template name="toc-item"></xsl:call-template>
</xsl:for-each>
</tbody>
</table>
</xsl:template>
<xsl:template name="toc-item" match="chapter/toc/toc-part/toc-div/toc-item">
<xsl:variable name="tocpg" >
<xsl:value-of select="concat('#P',current()/toc-pg/text())"/>
</xsl:variable>
<xsl:variable name="tocpgtag" select="translate($tocpg,'.', '-')" />
<xsl:variable name="chapternumber">
<!-- Get num attribute of parent node -->
<xsl:value-of select="ancestor::chapter[1]/#num"/>
</xsl:variable>
<xsl:variable name="itemlevel">
<xsl:value-of select="$ThisDocument//ntw:nums[#num=$chapternumber]/#word"></xsl:value-of>
</xsl:variable>
<xsl:variable name="tocitemlevel">
<xsl:value-of select="concat('toc-item-', $itemlevel,'-level')"></xsl:value-of>
</xsl:variable>
<table class="{$tocitemlevel}">
<tbody>
<tr>
<td class="toc-item-num">
<xsl:value-of select="current()/#num"/>
</td>
<td class="toc-title">
<xsl:value-of select="current()/toc-title"/>
</td>
<td class="toc-pg">
<a href="{$tocpgtag}">
<xsl:value-of select="current()/toc-pg"/>
</a>
</td>
</tr>
</tbody>
</table>
</xsl:template>
<!-- Index Templates Complete -->
<!-- Paragraph templates -->
<xsl:template name="section" match="section">
<!-- Variables-->
<xsl:variable name ="classname" >
<!--Get name attribute of current node -->
<xsl:value-of select="concat('section-',#level)"/>
</xsl:variable>
<xsl:variable name="chapternumber">
<!-- Get num attribute of parent node -->
<xsl:value-of select="ancestor::chapter[1]/#num"/>
</xsl:variable>
<xsl:variable name="sectnum">
<xsl:number level="any" count="section" format="1"/>
</xsl:variable>
<!--Create a string variable by concat string method -->
<xsl:variable name="sectionname">
<xsl:value-of select="concat('CH-',$chapternumber,'-SEC-0', $sectnum)"/>
</xsl:variable>
<!-- Template Content -->
<div class="{$classname}">
<a name="{$sectionname}"> </a>
<div class="section-title">
<span class="section-num">
<xsl:value-of select="#num"/>
</span>
<xsl:apply-templates/>
</div>
</div>
</xsl:template>
<!--<xsl:template name="para" match="section/para">
<xsl:variable name="count2">
<xsl:value-of select="count[child::node()]"></xsl:value-of>
</xsl:variable>
<xsl:choose>
<xsl:when test="$count2 >=1">
<div class="para">
<span class="phrase">
<xsl:value-of select="current()/phrase"/>
</span>
<xsl:apply-templates/>
</div>
</xsl:when>
<xsl:when test="$count2 < 1">
<span class="phrase">
<xsl:value-of select="current()/phrase"/>
</span>
<xsl:apply-templates mode="nr"/>
</xsl:when>
</xsl:choose>
</xsl:template> -->
<xsl:template name="para" match="section/para">
<xsl:choose>
<xsl:when test="contains()">
<div class="para">
<span class="phrase">
<xsl:value-of select="current()/phrase"/>
</span>
<xsl:apply-templates/>
</div>
</xsl:when>
</xsl:choose>
</xsl:template>
<xsl:template name="phrase" match="phrase">
<xsl:variable name="phrase">
<xsl:value-of select="concat('P',text())"/>
</xsl:variable>
<xsl:variable name="newphrase" select="translate($phrase,'.','-')"/>
<a>
<xsl:attribute name="name">
<xsl:value-of select="$newphrase"></xsl:value-of>
</xsl:attribute>
</a>
</xsl:template>
<!-- Table Templates -->
<xsl:template name ="table" match="table">
<table style="frame-{current()/#frame} width-{translate(current()/#width,'%','')}"><colgroup></colgroup>
<xsl:apply-templates/>
</table>
</xsl:template>
<xsl:template name="tbody" match="tgroup/tbody">
<tbody>
<xsl:for-each select="current()/row">
<xsl:call-template name="row"></xsl:call-template>
</xsl:for-each>
</tbody>
</xsl:template>
<xsl:template name="thead" match="tgroup/thead">
<xsl:value-of select="name()"></xsl:value-of>
<xsl:for-each select="current()/row">
<xsl:value-of select="name()"></xsl:value-of>
<tr>
<xsl:for-each select="current()/entry">
<xsl:call-template name="headentry"></xsl:call-template>
</xsl:for-each>
</tr>
</xsl:for-each>
</xsl:template>
<xsl:template name="colspec" match="colspec" >
<col class="colnum-{current()/#colnum} colname-{current()/#colname} colwidth-{translate(current()/#colwidth,'%','')}"/>
</xsl:template>
<xsl:template name="row" match="tbody/row">
<tr>
<xsl:for-each select="current()/entry">
<xsl:call-template name="entry" ></xsl:call-template>
</xsl:for-each>
</tr>
</xsl:template>
<xsl:template name="entry" match="entry">
<xsl:variable name="count">
<xsl:value-of select="count(preceding-sibling::* | following-sibling::*)"></xsl:value-of>
</xsl:variable>
<xsl:choose>
<xsl:when test="$count < 2">
<xsl:if test="position()=1">
<td>
<div class="para align-center">
<xsl:value-of select="para[position()=1]"/>
</div>
</td>
<td>
<div class="para">
<xsl:value-of select="following-sibling::node()"></xsl:value-of>
</div>
</td>
</xsl:if>
</xsl:when>
<xsl:when test="$count > 1">
<td>
<div class="para">
<!--xsl:value-of select="current()"/-->
<xsl:apply-templates/>
</div>
</td>
</xsl:when>
</xsl:choose>
</xsl:template>
<xsl:template name="headentry" >
<th>
<xsl:if test="translate(current()/#namest,'col','') != translate(current()/#nameend,'col','')">
<xsl:variable name="colspan">
<xsl:value-of select="translate(current()/#nameend,'col','') - translate(current()/#namest,'col','') + 1" />
</xsl:variable>
<xsl:attribute name="colspan">
<xsl:value-of select="$colspan"></xsl:value-of>
</xsl:attribute>
</xsl:if>
<div class="para">
<xsl:value-of select="current()/para/text()"/>
</div>
</th>
</xsl:template>
<!-- Table Templates complete -->
<!--List templates -->
<xsl:template name="orderedlist" match="orderedlist">
<ol class="orderedlist">
<xsl:apply-templates/>
</ol>
</xsl:template>
<xsl:template name="orderitem" match="orderlist/item">
<li class="item">
<xsl:apply-templates/>
</li>
</xsl:template>
<xsl:template name="orderitempara" match="item/para">
<xsl:variable name="itemnumber">
<xsl:value-of select="parent::item[1]/#num"/>
</xsl:variable><li class="item">
<div class="para">
<span class="item-num">
<xsl:value-of select="parent::item[1]/#num"/>
</span>
<xsl:apply-templates></xsl:apply-templates>
</div></li>
</xsl:template>
<!--List templates Complete -->
<!-- Paragraph templates Complete -->
<!-- Footnote Templates-->
<xsl:template match="footnote"><sup>
<a>
<xsl:attribute name="name"><xsl:text>footnoteref</xsl:text><xsl:number level="any" count="footnote" format="1"/></xsl:attribute>
<xsl:attribute name="href"><xsl:text>#footnote</xsl:text><xsl:number level="any" count="footnote" format="1"/></xsl:attribute>
<xsl:attribute name="class">
<xsl:text>tr_ftn</xsl:text><xsl:number level="any" count="footnote" format="1"/>
</xsl:attribute>
<xsl:number level="any" count="footnote" format="1"/>
</a></sup>
</xsl:template>
<xsl:template match="footnote" mode="footnote"><sup>
<li style="list-style-type:none;indent:0">
<a>
<xsl:attribute name="name"><xsl:text>footnote</xsl:text><xsl:number level="any" count="footnote" format="1"/></xsl:attribute>
<xsl:attribute name="href"><xsl:text>#footnoteref</xsl:text><xsl:number level="any" count="footnote" format="1"/></xsl:attribute>
<xsl:attribute name="class">
<xsl:text>tr_ftn</xsl:text><xsl:number level="any" count="footnote" format="1"/>
</xsl:attribute>
<xsl:number level="any" count="footnote" format="1"/>
</a>
<xsl:text> </xsl:text>
<xsl:apply-templates/>
</li></sup>
</xsl:template>
<xsl:template match="footnote/para/uri">
<a>
</a>
</xsl:template>
<!-- Footnote Templates Complete -->
<xsl:template match="content-style">
<xsl:choose>
<xsl:when test="#format='smallcaps'">
<xsl:value-of select="translate(normalize-space(.),'ABCDEFGHIJKLMNOPQRSTUVWXZ','abcdefghijklmnopqrstuvwxyz')"/>
</xsl:when>
<xsl:when test="#format='superscript'">
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- Namespace ntw-->
<ntw:nums num="01" word="first"></ntw:nums>
<ntw:nums num="02" word="second"></ntw:nums>
<ntw:nums num="03" word="third"></ntw:nums>
<ntw:nums num="04" word="forth"></ntw:nums>
<ntw:nums num="05" word="fifth"></ntw:nums>
<ntw:nums num="06" word="sixth"></ntw:nums>
<ntw:nums num="07" word="seventh"></ntw:nums>
<ntw:nums num="08" word="eighth"></ntw:nums>
<ntw:nums num="09" word="nighth"></ntw:nums>
<ntw:nums num="10" word="tenth"></ntw:nums>
<!-- Namespace ntw ends -->
</xsl:stylesheet>
Thanks
As I am not exactly sure on which place you want to count al the <colspec> elements here an explanation of count():
You can use count(node-set) (replace node-set with your desired node-set to count) to count all the nodes from where you start it. For example:
Count all <colspec> elements in XML:
<xsl:value-of select="count(//colspec)" />
Count all <colspec> elements from the path you are now:
<xsl:value-of select="count(colspec)" />
Count all <colspec> elements from the path you are now below element <tgroup>:
<xsl:value-of select="count(tgroup/colspec)" />
Your question about the " is not clear to me. Please keep in mind that HTML and XML have some special characters which you never can display as is in source code. See next:
HTML special characters: http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references#Character_entity_references_in_HTML
XML special characters: http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references#Predefined_entities_in_XML
Hope it helps you out!
I have the below part of my XML Document. here when i run my xslt on this XML document, the col class ... inside colgroup is getting called, colgroup is getting called but end tag of col class is not getting called. please let me know how do i close col class... the last code contains my html output of xml.
<table frame="all" width="100%">
<tgroup cols="2">
<colspec colnum="1" colname="col1" colwidth="18%"/>
<colspec colnum="2" colname="col2" colwidth="82%"/>
<thead>
<row>
<entry namest="col1" nameend="col2">
<para>A timeline of British Virgin Islands company law</para>
</entry>
</row>
</thead>
<tbody>
<row>
<entry>
<para>1884</para>
</entry>
<entry>
<para>Companies Act passed into law.</para>
</entry>
</row>
<row>
<entry>
<para>1984</para>
</entry>
<entry>
<para>International Business Companies Act passed into law.</para>
</entry>
</row>
<row>
<entry>
<para>2004</para>
</entry>
<entry>
<para>BVI Business Companies Act passed into law, coming into force on 1 January 2005.</para>
</entry>
</row>
<row>
<entry>
<para>2005</para>
</entry>
<entry>
<para>All three corporate statutes exist in parallel and it is possible to incorporate companies under any of them.</para>
</entry>
</row>
<row>
<entry>
<para>2006</para>
</entry>
<entry>
<para>Incorporation provisions in the International Business Companies Act and the Companies Act are repealed on 31 December 2005; the Acts remain in force but new companies may only be incorporated under the BVI Business Companies Act.</para>
</entry>
</row>
<row>
<entry>
<para>2007</para>
</entry>
<entry>
<para>International Business Companies Act repealed on 31 December 2006. Transitional provisions come into effect for companies incorporated under that act.</para>
</entry>
</row>
<row>
<entry>
<para>2009</para>
</entry>
<entry>
<para>Companies Act repealed on 31 December 2008. Transitional provisions come into effect for companies incorporated under that Act.</para>
</entry>
</row>
</tbody>
</tgroup>
</table>
and below is my 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:variable name="ThisDocument" select="document('')"/>
<xsl:template match="/">
<html>
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=UTF-8"/>
<title>
<xsl:value-of select="chapter/title"/>
</title>
<link rel="stylesheet" href="er:#css" type="text/css"/>
</head>
<body>
<xsl:apply-templates/>
<hr/>
<section class="tr_footnotes">
<xsl:apply-templates select="//footnote"
mode="footnote"/>
</section>
</body>
</html>
</xsl:template>
<xsl:template match="chapter">
<section>
<div class="chapter">
<a name="BVI-CH-{#num}"/>
<xsl:variable name="cnum">
<xsl:choose>
<xsl:when test="starts-with(#num,'0')">
<xsl:value-of select="substring-after(#num,'0')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="#num"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<div class="chapter-title">
<span class="chapter-num">
<xsl:value-of select="concat('Chapter ',$cnum,' ')"/>
</span>
<xsl:apply-templates select="title"/>
</div>
<xsl:apply-templates select="child::node()[not(self::title)]"/>
</div>
</section>
</xsl:template>
<xsl:template match="chapter/para">
<div class="para align-right">
<span class="format-smallcaps">Para</span>.
</div>
</xsl:template>
<!-- Index templates -->
<xsl:template name="toc" match="chapter/toc">
<div class="toc">
<xsl:call-template name="toc-part"/>
</div>
</xsl:template>
<xsl:template name="toc-part" match="chapter/toc/toc-part">
<div class="toc-part">
<xsl:call-template name="toc-div"/>
</div>
</xsl:template>
<xsl:template name="toc-div" match="chapter/toc/toc-part/toc-div">
<table class="toc-div">
<tbody>
<xsl:for-each select="current()/toc-part/toc-div/*">
<xsl:call-template name="toc-item"/>
</xsl:for-each>
</tbody>
</table>
</xsl:template>
<xsl:template name="toc-item" match="chapter/toc/toc-part/toc-div/toc-item">
<xsl:variable name="tocpg">
<xsl:value-of select="concat('#P',current()/toc-pg/text())"/>
</xsl:variable>
<xsl:variable name="tocpgtag" select="translate($tocpg,'.', '-')"/>
<xsl:variable name="chapternumber">
<!-- Get num attribute of parent node -->
<xsl:value-of select="ancestor::chapter[1]/#num"/>
</xsl:variable>
<xsl:variable name="itemlevel">
<xsl:value-of select="$ThisDocument//ntw:nums[#num=$chapternumber]/#word"/>
</xsl:variable>
<xsl:variable name="tocitemlevel">
<xsl:value-of select="concat('toc-item-', $itemlevel,'-level')"/>
</xsl:variable>
<table class="{$tocitemlevel}">
<tbody>
<tr>
<td class="toc-item-num">
<xsl:value-of select="current()/#num"/>
</td>
<td class="toc-title">
<xsl:value-of select="current()/toc-title"/>
</td>
<td class="toc-pg">
<a href="{$tocpgtag}">
<xsl:value-of select="current()/toc-pg"/>
</a>
</td>
</tr>
</tbody>
</table>
</xsl:template>
<!-- Index Templates Complete -->
<!-- Paragraph templates -->
<xsl:template name="section" match="section">
<!-- Variables-->
<xsl:variable name="classname">
<!--Get name attribute of current node -->
<xsl:value-of select="concat('section-',#level)"/>
</xsl:variable>
<xsl:variable name="chapternumber">
<!-- Get num attribute of parent node -->
<xsl:value-of select="ancestor::chapter[1]/#num"/>
</xsl:variable>
<xsl:variable name="sectnum">
<xsl:number level="any" count="section" format="1"/>
</xsl:variable>
<!--Create a string variable by concat string method -->
<xsl:variable name="sectionname">
<xsl:value-of select="concat('CH-',$chapternumber,'-SEC-0', $sectnum)"/>
</xsl:variable>
<!-- Template Content -->
<div class="{$classname}">
<a name="{$sectionname}"> </a>
<div class="section-title">
<span class="section-num">
<xsl:value-of select="#num"/>
</span>
<xsl:apply-templates select="title"/>
</div>
<xsl:apply-templates select="child::node()[not(self::title)]"/>
</div>
</xsl:template>
<xsl:template name="para" match="section/para">
<div class="para">
<xsl:apply-templates select="phrase"/>
<span class="phrase">
<xsl:value-of select="current()/phrase"/>
</span>
<xsl:apply-templates select="child::node()[not(self::phrase)]"/>
</div>
</xsl:template>
<xsl:template name="phrase" match="phrase">
<xsl:variable name="phrase">
<xsl:value-of select="concat('P',text())"/>
</xsl:variable>
<xsl:variable name="newphrase" select="translate($phrase,'.','-')"/>
<a>
<xsl:attribute name="name"><xsl:value-of select="$newphrase"></xsl:value-of></xsl:attribute>
</a>
</xsl:template>
<!-- Table Templates -->
<xsl:template name="table" match="table">
<table style="frame-{current()/#frame} width-{translate(current()/#width,'%','')}">
<xsl:apply-templates/>
</table>
</xsl:template>
<xsl:template match="tgroup">
<colgroup>
<xsl:apply-templates select=".//colspec"/>
</colgroup>
<xsl:apply-templates select="child::node()[not(self::colspec)]"/>
</xsl:template>
<xsl:template name="tbody" match="tgroup/tbody">
<tbody>
<xsl:for-each select="current()/row">
<xsl:call-template name="row"/>
</xsl:for-each>
</tbody>
</xsl:template>
<xsl:template name="thead" match="tgroup/thead">
<xsl:for-each select="current()/row"><thead>
<tr>
<xsl:for-each select="current()/entry">
<xsl:call-template name="headentry"/>
</xsl:for-each>
</tr>
</thead>
</xsl:for-each>
</xsl:template>
<xsl:template name="colspec" match="colspec">
<col class="colnum-{current()/#colnum} colname-{current()/#colname} colwidth-{translate(current()/#colwidth,'%','')}"></col>
</xsl:template>
<xsl:template name="row" match="tbody/row">
<tr>
<xsl:for-each select="current()/entry">
<xsl:call-template name="entry"/>
</xsl:for-each>
</tr>
</xsl:template>
<xsl:template name="entry" match="entry">
<xsl:variable name="count">
<xsl:value-of select="count(preceding-sibling::* | following-sibling::*)"/>
</xsl:variable>
<xsl:choose>
<xsl:when test="$count < 2">
<xsl:if test="position()=1">
<td>
<div class="para align-center">
<xsl:value-of select="para[position()=1]"/>
</div>
</td>
<td>
<div class="para">
<xsl:value-of select="following-sibling::node()"/>
</div>
</td>
</xsl:if>
</xsl:when>
<xsl:when test="$count > 1">
<td>
<div class="para">
<xsl:apply-templates/>
</div>
</td>
</xsl:when>
</xsl:choose>
</xsl:template>
<xsl:template name="headentry">
<th>
<xsl:if test="translate(current()/#namest,'col','') != translate(current()/#nameend,'col','')">
<xsl:variable name="colspan">
<xsl:value-of select="translate(current()/#nameend,'col','') - translate(current()/#namest,'col','') + 1"/>
</xsl:variable>
<xsl:attribute name="colspan"><xsl:value-of select="$colspan"></xsl:value-of></xsl:attribute>
</xsl:if>
<div class="para">
<xsl:value-of select="current()/para/text()"/>
</div>
</th>
</xsl:template>
<!-- Table Templates complete -->
<!--List templates -->
<xsl:template name="orderedlist" match="orderedlist">
<ol class="orderedlist">
<xsl:apply-templates/>
</ol>
</xsl:template>
<xsl:template name="orderitem" match="orderlist/item">
<li class="item">
<xsl:apply-templates/>
</li>
</xsl:template>
<xsl:template name="orderitempara" match="item/para">
<xsl:variable name="itemnumber">
<xsl:value-of select="parent::item[1]/#num"/>
</xsl:variable>
<li class="item">
<div class="para">
<span class="item-num">
<xsl:value-of select="parent::item[1]/#num"/>
</span>
<xsl:apply-templates/>
</div>
</li>
</xsl:template>
<!--List templates Complete -->
<!-- Paragraph templates Complete -->
<!-- Footnote Templates-->
<xsl:template match="footnote">
<sup>
<a>
<xsl:attribute name="name"><xsl:text>footnoteref</xsl:text><xsl:number level="any" count="footnote" format="1"/></xsl:attribute>
<xsl:attribute name="href"><xsl:text>#footnote</xsl:text><xsl:number level="any" count="footnote" format="1"/></xsl:attribute>
<xsl:attribute name="class"><xsl:text>tr_ftn</xsl:text><xsl:number level="any" count="footnote" format="1"/></xsl:attribute>
<xsl:number level="any" count="footnote" format="1"/>
</a>
</sup>
</xsl:template>
<xsl:template match="footnote" mode="footnote">
<sup>
<li style="list-style-type:none;indent:0">
<a>
<xsl:attribute name="name"><xsl:text>footnote</xsl:text><xsl:number level="any" count="footnote" format="1"/></xsl:attribute>
<xsl:attribute name="href"><xsl:text>#footnoteref</xsl:text><xsl:number level="any" count="footnote" format="1"/></xsl:attribute>
<xsl:attribute name="class"><xsl:text>tr_ftn</xsl:text><xsl:number level="any" count="footnote" format="1"/></xsl:attribute>
<xsl:number level="any" count="footnote" format="1"/>
</a>
<xsl:text> </xsl:text>
<xsl:apply-templates/>
</li>
</sup>
</xsl:template>
<xsl:template match="footnote/para/uri">
<xsl:variable name="url1">
<xsl:value-of select="translate(#href, '<','')" />
</xsl:variable>
<xsl:variable name="url2">
<xsl:value-of select="translate($url1, '>','')" />
</xsl:variable>
<a href="{$url2}">
<xsl:value-of select="." />
</a>
</xsl:template>
<!-- Footnote Templates Complete -->
<xsl:template match="content-style">
<xsl:choose>
<xsl:when test="#format='smallcaps'">
<xsl:value-of select="translate(normalize-space(.),'ABCDEFGHIJKLMNOPQRSTUVWXZ','abcdefghijklmnopqrstuvwxyz')"/>
</xsl:when>
<xsl:when test="#format='superscript'">
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- Namespace ntw-->
<ntw:nums num="01" word="first"/>
<ntw:nums num="02" word="second"/>
<ntw:nums num="03" word="third"/>
<ntw:nums num="04" word="forth"/>
<ntw:nums num="05" word="fifth"/>
<ntw:nums num="06" word="sixth"/>
<ntw:nums num="07" word="seventh"/>
<ntw:nums num="08" word="eighth"/>
<ntw:nums num="09" word="nighth"/>
<ntw:nums num="10" word="tenth"/>
<!-- Namespace ntw ends -->
</xsl:stylesheet>
HTML output of xml.
table style="frame-all width-100">
<colgroup>
<col class="colnum-1 colname-col1 colwidth-18"> //here / is missing in the end
<col class="colnum-2 colname-col2 colwidth-82">//here / is missing in the end
</colgroup>
Thanks
Welcome to Stack Overflow!
Your stylesheet does not specify an output method, but your output is recognizably HTML. So your stylesheet is using the HTML output method, and not the XML output method. In the HTML output method, elements which are always empty (like col) use an SGML-style end-tag, so the output you show is correct.
If you want XML output, add an xsl:output element to the stylesheet (as the first child of xsl:stylesheet) and specify method="xml" on it, thus:
<xsl:output method="xml"/>
(Note that if you are looking to create XHTML output, you will want to put your output elements in the XHTML namespace.)
When I add an output element to the stylesheet, the colgroup element in the output takes the following form, which appears to be what you're looking for:
<colgroup>
<col class="colnum-1 colname-col1 colwidth-18"/>
<col class="colnum-2 colname-col2 colwidth-82"/>
</colgroup>