I'm having trouble listing a combination of text and child nodes via xsl.
My xml is generated automatically by a program called Doxygen. This section is
a program listing. No matter what I do, I can't seem to get the child elements
of <codeline> (mostly sp's), if I want the whole text line.
The xml is (I have just pulled out a few lines):
<?xml version="1.0" encoding="UTF-8"?>
<doxygen>
<compounddef>
<codelisting>
<programlisting>
<codeline lineno="1">
<highlight
class="preprocessor">#pragma<sp/>warning<sp/>(disable<sp/>:<sp/>4786)<sp/>//<sp/>Disable<sp/>STL<sp/>warning<sp/>spam</highlight>
</codeline>
<codeline lineno="2">
<highlight class="preprocessor"/>
<highlight class="normal"/>
</codeline>
<codeline lineno="3">
<highlight class="normal"/>
<highlight
class="preprocessor">#include<sp/><iomanip></highlight>
<highlight class="normal"/>
</codeline>
<codeline lineno="8">
<highlight class="normal"/>
<highlight class="preprocessor">#include<sp/>"<ref
refid="OurPrograms_8h" kindref="compound">OurPrograms.h</ref>"</highlight>
<highlight class="normal"/>
</codeline>
<codeline lineno="9">
<highlight class="normal"/>
<highlight
class="preprocessor">#include<sp/>"GMFSDate/GMFSDate.h"</highlight>
<highlight class="normal"/>
</codeline>
<codeline lineno="10">
<highlight class="normal"/>
<highlight class="preprocessor">#include<sp/>"<ref
refid="DB_Conn_8hpp"
kindref="compound">SQLSVRDB/DB_Conn.hpp</ref>"</highlight>
<highlight class="normal"/>
</codeline>
<codeline lineno="34" refid="classOurCompany_1s0" refkind="member">
<highlight class="normal"/>
<highlight class="keyword">const</highlight>
<highlight class="normal">
<sp/>
<ref refid="classOurCompany_1w0"
kindref="member">OurCompany::ErrCode</ref>
<sp/>
<ref refid="classOurCompany_1s0"
kindref="member">OurCompany::ERR_NONE</ref>
<sp/>=<sp/>0;</highlight>
</codeline>
<codeline lineno="35" refid="classOurCompany_1s1" refkind="member">
<highlight class="normal"/>
<highlight class="keyword">const</highlight>
<highlight class="normal">
<sp/>
<ref refid="classOurCompany_1w0"
kindref="member">OurCompany::ErrCode</ref>
<sp/>
<ref refid="classOurCompany_1s1"
kindref="member">OurCompany::ERR_BBX</ref>
<sp/>=<sp/>1;</highlight>
</codeline>
</programlisting>
</codelisting>
</compounddef>
</doxygen>
The xsl I am using is:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Code listing for a nominated function. -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template match="/">
<html>
<head>
<title>A function</title>
<link rel="stylesheet" href="doxygen.css"
type="text/css"/>
</head>
<body>
<table>
<xsl:for-each
select="doxygen/compounddef/programlisting/codeline">
<tr>
<td>
<xsl:value-of
select="@lineno"/>
</td>
<td>
<xsl:for-each
select="highlight">
<span
class="<xsl:value-of select="@class"/>>
<!-- Doesn't seem to matter
what I do here, I can get the whole text, ignoring sp elements, or I can get
the first sp element, -->
<!-- or I can get the first
text element only, depending on what I do -->
<!-- I have tried
xsl:for-each loops, I've tried matching templates, but I still can't seem to
get it to work. -->
<xsl:for-each select="text()">
<xsl:value-of select="."/>
</xsl:for-each>
</span>
</xsl:for-each>
</td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Can anyone tell me how I can access each child element, and still get all of
the text?
As you can probably see from the question, I wouldn't call myself an
experienced xsl user yet.
Many thanks
Karen
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list