xsl-list
[Top] [All Lists]

Displaying a combination of text and child nodes

2003-07-07 16:16:07
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/>&lt;iomanip&gt;</highlight>
                <highlight class="normal"/>
        </codeline>
        <codeline lineno="8">
                <highlight class="normal"/>
                <highlight class="preprocessor">#include<sp/>&quot;<ref 
refid="OurPrograms_8h" kindref="compound">OurPrograms.h</ref>&quot;</highlight>
                <highlight class="normal"/>
        </codeline>
        <codeline lineno="9">
                <highlight class="normal"/>
                <highlight 
class="preprocessor">#include<sp/>&quot;GMFSDate/GMFSDate.h&quot;</highlight>
                <highlight class="normal"/>
        </codeline>
        <codeline lineno="10">
                <highlight class="normal"/>
                <highlight class="preprocessor">#include<sp/>&quot;<ref 
refid="DB_Conn_8hpp" 
kindref="compound">SQLSVRDB/DB_Conn.hpp</ref>&quot;</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="&lt;xsl:value-of select=&quot;@class&quot;/&gt;>
                                                  <!-- 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



<Prev in Thread] Current Thread [Next in Thread>