By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,876 Members | 1,191 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,876 IT Pros & Developers. It's quick & easy.

xsl apply-templates select=not(...)

P: n/a
Hello,

I have a XML document which is typically :

<course>
<section>
<title>Foo</title>
There comes the text
</section>
<section>
<title>Foo</title>
There comes the text
</section>
</course>

I'd like to indent the "There comes the text" part, but not the title.
This is what I tried, but unfortunately it doesn't work :

<xsl:template match="course/section">
<xsl:apply-templates select="title"/>
<ul>
<xsl:apply-templates select="*[not(title)]"/>
</ul>
</xsl:template>

Could someone give me advice on this. I'd like to avoid the for-if
combination if possible.

Thanks in advance,
--
_|_|_| CnS
_|_| for(n=0;b;n++)
_| b&=b-1; /*pp.47 K&R*/
Jul 20 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
In article <Xn****************************@213.228.0.136>,
Cyrille \"cns\" Szymanski <cn**@cns.invalid> wrote:

% I have a XML document which is typically :
%
% <course>
% <section>
% <title>Foo</title>
% There comes the text
% </section>

From a design perspective, I think you're better off if you make
section have element content (that is, you wrap all your text in
additional elements). For one thing, if that's valid, then this must
also be valid

% <section>
Here is some text
% <title>Foo</title>
% </section>

which is probably not desirable. For another, you have to guess at the
structure if there's more than one paragraph of data, which goes against
the point of using xml in the first place.

% I'd like to indent the "There comes the text" part, but not the title.
% This is what I tried, but unfortunately it doesn't work :
%
% <xsl:template match="course/section">
% <xsl:apply-templates select="title"/>
% <ul>
% <xsl:apply-templates select="*[not(title)]"/>

Try select="node()[not(title)]", or if it's really just text,
select="text()".
--

Patrick TJ McPhee
East York Canada
pt**@interlog.com
Jul 20 '05 #2

P: n/a
Patrick TJ McPhee wrote:
In article <Xn****************************@213.228.0.136>,
Cyrille \"cns\" Szymanski <cn**@cns.invalid> wrote:
% I'd like to indent the "There comes the text" part, but not the title.
% This is what I tried, but unfortunately it doesn't work :
%
% <xsl:template match="course/section">
% <xsl:apply-templates select="title"/>
% <ul>
% <xsl:apply-templates select="*[not(title)]"/>

Try select="node()[not(title)]",


This selects all child nodes of section that have no _child node(s)_
called title. Try "node()[not(self::title)]" instead.

--
Johannes Koch
In te domine speravi; non confundar in aeternum.
(Te Deum, 4th cent.)

Jul 20 '05 #3

P: n/a
> Patrick TJ McPhee wrote:
In article <Xn****************************@213.228.0.136>,
Cyrille \"cns\" Szymanski <cn**@cns.invalid> wrote:
% I'd like to indent the "There comes the text" part, but not the
title. % This is what I tried, but unfortunately it doesn't work :
%
% <xsl:template match="course/section">
% <xsl:apply-templates select="title"/>
% <ul>
% <xsl:apply-templates select="*[not(title)]"/>

Try select="node()[not(title)]",


This selects all child nodes of section that have no _child node(s)_
called title. Try "node()[not(self::title)]" instead.


Thanks. In fact I had added the self:: part since I read a message that
pointed out this issue.

--
_|_|_| CnS
_|_| for(n=0;b;n++)
_| b&=b-1; /*pp.47 K&R*/
Jul 20 '05 #4

P: n/a
> From a design perspective, I think you're better off if you make
section have element content (that is, you wrap all your text in
additional elements). For one thing, if that's valid, then this must
also be valid


You're absolutely right, unfortunately, I am not free to do so since I'm
using existing XML documents that are already written that way.

Thanks for help,
--
_|_|_| CnS
_|_| for(n=0;b;n++)
_| b&=b-1; /*pp.47 K&R*/
Jul 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.