 |
 |
 |
> I receive XML similar to that shown below:
>
> <bodyFrag>
> <p>title</p>
> <ProgAbs>some text</ProgAbs>
> <ProgAbs>More text</ProgAbs>
> <ProgAbs>Even more</ProgAbs>
> <p>Paragraph</p>
> <p>Beispiel:</p>
> <ProgAbs>some text</ProgAbs>
> <ProgAbs>More text</ProgAbs>
> <ProgAbs>Even more</ProgAbs>
> </bodyFrag>
>
> I need to process it as follows:
>
> 1. When I see a <p> containing 'title', output it in
> some way. (I
> can do this part).
A description of the processing that starts "When I see" is not a good place
to start. It suggests you're thinking in terms of sequential processing.
>
> 2, Select only the immediately following <ProgAbs>
> sibling elements.
> I.e. the 3 ProgAbs elements with content immediately following the <p>
> element selected in 1 above.
>
> Using 'following-sibling::ProgAbs' gives me all the siblings
> of that name,
> as it should. I just need to know how to construct an
> expression to select
> only those <ProgAbs> that follow on immendiately after the
> <p> element.
>
In XSLT 2.0 you can do this with for-each-group.
In 1.0 there are two main approaches: one is to use
generate-id(preceding-sibling::p[1]) as a grouping key for the ProgAbs
elements, and then use Muenchian grouping. The other is to use head-tail
recursion on the sequence of siblings: so you call a template passing the
full list of siblings as a parameter, this then calls itself to process the
elements after the first if there's another ProgAbs, or returns if there
isn't.
Michael Kay
http://www.saxonica.com/
|
 | 

|  |
These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.
|  |
| |
 |
 |
 |