cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Geert Josten <Geert.Jos...@daidalos.nl>
Subject Re: include specific element with cinclude
Date Tue, 01 Mar 2005 18:06:52 GMT

> I've made various attempts to be more specific in the XPath and nothing
> works. I've tried the following:
> 
> <cinclude:include xmlns:cinclude="http://apache.org/cocoon/include/1.0" 
>   src="http://localhost/something.xml"
> select="//*[local-name()='paragraph[2]']/."/>

local-name() returns the name of the element without the namespace prefix. You added a predicate

test, but added it to the compare string for the local-name(). Move it to _after_ the original
close 
bracket, like:

select="//*[local-name()='paragraph'][2]"

(you can drop the /. at the end)

This selects _every_ second paragraph within any parent that occurs.

> <cinclude:include xmlns:cinclude="http://apache.org/cocoon/include/1.0" 
>   src="http://localhost/something.xml"
> select="//*[local-name()='page']/paragraph[2]"/>

This, for starters, requires that paragraph has element 'page' as parent.
Moreover, it looks for 'paragraph' elements without namespace.

> <cinclude:include xmlns:cinclude="http://apache.org/cocoon/include/1.0" 
>   src="http://localhost/something.xml"
> select="//*[local-name()='page']/paragraph[2]/."/>

Does the same as previous..

> <cinclude:include xmlns:cinclude="http://apache.org/cocoon/include/1.0" 
>   src="http://localhost/something.xml"
> select="//*[local-name()='page/paragraph[2]']/."/>

Again, you added the predicates to the compare string, that won't work

> <cinclude:include xmlns:cinclude="http://apache.org/cocoon/include/1.0" 
>   src="http://localhost/something.xml"
> select="//*[local-name()='page']/paragraph/[2]"/>

Illegal XPath. You can't specify a predicated directly after a /. Add at least one dot between,
but 
it is easier just to drop the /.. :-)

In short, you are looking for either:

//*[local-name()='paragraph'][2]

or

//*[local-name()='page']/*[local-name()='paragraph'][2]

Two additional notes:
* //paragraph[2] is not the same as (//paragraph)[2]
* Specify the namespace of paragraph in you XML that contains the cincludes and use the prefix
in 
the select expressions. Matching through local-name() is not a good method.

Cheers,
Geert

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Mime
View raw message