[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

RE: [xsl] Displaying a combination of text and child nodes


Subject: RE: [xsl] Displaying a combination of text and child nodes
From: "Karen Dunstall" <kdunstall@xxxxxxxxxxxxxxx>
Date: Tue, 8 Jul 2003 11:59:51 +1000

Thanks Lars
The *|text() worked.  
Much appreciated.

Also, thanks for the hint with the attribute value template.  Much, much more pleasant.

Karen

-----Original Message-----
From: Lars Huttar [mailto:lars_huttar@xxxxxxx]
Sent: Tuesday, 8 July 2003 11:09 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE: [xsl] Displaying a combination of text and child nodes


Karen,

> 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">
...

> 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="/">
...
> 					<xsl:for-each 
> select="doxygen/compounddef/programlisting/codeline">
> 						<tr>
> 							<td>
> 								

For one thing, maybe this is just an
artifact of how you excerpted your XML, but the way you show it,
the path to <codeline> is
  /doxygen/compounddef/codelisting/programlisting/codeline
whereas your <xsl:foreach> says
   select="doxygen/compounddef/programlisting/codeline"
In other words, "codelisting/" is missing.


> <xsl:for-each select="highlight">
> 								
> 	<span class="&lt;xsl:value-of select=&quot;@class&quot;/&gt;>

This isn't what you asked about, but probably instead of the above
you want to use an Attribute Value Template:
     <span class="{@class}">

Much more pleasant, isn't it?  :-)

> 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.  -->

Did you try <xsl:for-each select="*|text()"> ?

* will select child element nodes, and text() will select child text
nodes. Unioned together with "|", you get both.
Or maybe you want <xsl:for-each select="sp|text()">.

Another alternative would be to use apply-templates:
 <xsl:apply-templates select="*|text()" />
Then you could create a template for processing <sp>s,
another for text nodes, another for <ref>s, etc.

(If you were trying <xsl:value-of ...> without a <xsl:for-each>,
that would be why you only got the first element or text node;
<xsl:value-of select="nodeset"/> converts only the *first* node
in nodeset into a string.)

HTH,
Lars


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



Current Thread
Keywords