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

[xsl]Retrieve node-set based on position relative to identical siblings


Subject: [xsl]Retrieve node-set based on position relative to identical siblings
From: Martin Kupisch <Kupisch@xxxxxxxxxxxxxx>
Date: Wed, 13 Nov 2002 14:20:55 +0100

Hello everyone,

I would like to build a node-set assigned to a variable that is used
throughout the stylesheet several times. The structure of the input is
as follows: there are lot of 'productGroup'-elements that contain
'product'-elements that contain further children. Each product contains
an 'id'-attribute. Each 'productGroup' can contain several 'products'
with identical ids. What I need to do is to select all products with
certain ids with a position relative to all products with the same id. I
try to illustrate with an example.

Input:

<productGroup>
    <product id ="a">        <-
    <product id ="a">        <-
    <product id ="a">
    <product id ="b">        <-
    <product id ="b">
    <product id ="c">
<productGroup>
<productGroup>
    <product id ="d">
    <product id ="e">        <-
    <product id ="e">        <-
<productGroup>

products with the same id are always siblings in the same productGroup.
The positons to choose are only known to my application so I provide
them as a parameter through my Java API to the stylesheet named
'positions' with a value like this:
    ;a:,1,2,;b:,1,;e:,1,2,;
which means for example take products with id 'a' that have position 1
and 2 relative to all a's and so on, ie take all products marked in the
example above.I tried the following expression to get these nodes:
'//product[contains(substring-before(substring-after($positions,
concat(';', @id, ':')), ';'), concat(',',
count(preceding-sibling::product[@id=./@id])+1, ','))]'
                            <-
(1)                                                         ->
<-
(2)                                               ->

<-                    (3)
->                                   <-
(4)                           ->
, which means for each product: get the substring after the string
containing the id at (3), for example ;a: up to the next ';' (1), for
example ,1,2, which would be the positions and decide wether (2) is
contained in $positions, that would be something like ,1,. I guess the
approach does not work because in the predicate in (4) the context node
switched and the expression always evaluates to true.

Any comments on the overall approach or any other suggestions how to
handle this problem?
Thanks for any help, Martin.


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



Current Thread