You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-users@xmlgraphics.apache.org by Faehndrich Philippe <ph...@bluewin.ch> on 2009/12/17 14:15:57 UTC

Number of elements with a given attribute

Hello,

In a piece of theater, I have some verses that are split between different 
roles.

All verses without a part attribute are complete verses.
<role name='...'>
  <verse>...</verse>
  <verse>...</verse>
  ...
</role>

The other are tagged on the following model:
<role name='...'>
   ...
  <verse>...</verse>
  <verse part="beginning">...</verse>
</role>
<role name='...'>
  <verse part="continuation">...</verse>
</role>
<role name='...'>
  <verse part="continuation">...</verse>
</role>
<role name='...'>
  <verse part="end">...</verse>
  <verse>...</verse>
  ...
</role>

I need to know if a continuation is the only one between beginning and end, 
the first or the second of two, the first, second or third of three, and so 
on.

<xsl:value-of select="count(preceding::verse[@part != 'beginning']) "/> gives 
me the count of all preceding verses with part attribute other 
than "beginning" from the beginning of the piece, what is not what I want. 
I wish to have the count of preceding parts of verse from the last beginning 
part.

Could someone help me?

Thanks in advance,
Ph. Faehndrich



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


Re: Number of elements with a given attribute

Posted by Gregory Buchenberger <gr...@eightfoldconsulting.com>.
A good place for XSLT, XSL, XPath questions is the XSL mailing list at

http://www.mulberrytech.com/xsl/xsl-list/




On Thu, 2009-12-17 at 15:34 +0100, Pascal Sancho wrote:
> Hi,
> 
> This is a pure XSLT/Xpath related question...
> Nothing to do with FOP. For such questions, you should ask on the right 
> list.
> 
> That said, IMHO you should select a nodeset using actual index position 
> (count(preceding::*) does the trick)
> To find the last node that is a boudary should be done with following 
> expression:
> preceding::verse[@part != 'beginning'][1]
> 
> Note that if you put your nodeset in a xsl:variable, you can have some 
> troubles.
> Xalan (see [1]) or MSXML (see [2]) provide extended function for that 
> purpose.
> 
> [1] http://xml.apache.org/xalan-j/extensionslib.html#nodeset
> [2] http://msdn.microsoft.com/en-us/library/hz88kef0%28VS.71%29.aspx
> 
> HTH,
> Pascal
> 
> 
> Faehndrich Philippe a écrit :
> > Hello,
> >
> > In a piece of theater, I have some verses that are split between different
> > roles.
> >
> > All verses without a part attribute are complete verses.
> > <role name='...'>
> >   <verse>...</verse>
> >   <verse>...</verse>
> >   ...
> > </role>
> >
> > The other are tagged on the following model:
> > <role name='...'>
> >    ...
> >   <verse>...</verse>
> >   <verse part="beginning">...</verse>
> > </role>
> > <role name='...'>
> >   <verse part="continuation">...</verse>
> > </role>
> > <role name='...'>
> >   <verse part="continuation">...</verse>
> > </role>
> > <role name='...'>
> >   <verse part="end">...</verse>
> >   <verse>...</verse>
> >   ...
> > </role>
> >
> > I need to know if a continuation is the only one between beginning and end,
> > the first or the second of two, the first, second or third of three, and so
> > on.
> >
> > <xsl:value-of select="count(preceding::verse[@part != 'beginning']) "/> gives
> > me the count of all preceding verses with part attribute other
> > than "beginning" from the beginning of the piece, what is not what I want.
> > I wish to have the count of preceding parts of verse from the last beginning
> > part.
> >
> > Could someone help me?
> >
> > Thanks in advance,
> > Ph. Faehndrich
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org
> 



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


Re: Number of elements with a given attribute

Posted by Pascal Sancho <pa...@takoma.fr>.
Hi,

This is a pure XSLT/Xpath related question...
Nothing to do with FOP. For such questions, you should ask on the right 
list.

That said, IMHO you should select a nodeset using actual index position 
(count(preceding::*) does the trick)
To find the last node that is a boudary should be done with following 
expression:
preceding::verse[@part != 'beginning'][1]

Note that if you put your nodeset in a xsl:variable, you can have some 
troubles.
Xalan (see [1]) or MSXML (see [2]) provide extended function for that 
purpose.

[1] http://xml.apache.org/xalan-j/extensionslib.html#nodeset
[2] http://msdn.microsoft.com/en-us/library/hz88kef0%28VS.71%29.aspx

HTH,
Pascal


Faehndrich Philippe a écrit :
> Hello,
>
> In a piece of theater, I have some verses that are split between different
> roles.
>
> All verses without a part attribute are complete verses.
> <role name='...'>
>   <verse>...</verse>
>   <verse>...</verse>
>   ...
> </role>
>
> The other are tagged on the following model:
> <role name='...'>
>    ...
>   <verse>...</verse>
>   <verse part="beginning">...</verse>
> </role>
> <role name='...'>
>   <verse part="continuation">...</verse>
> </role>
> <role name='...'>
>   <verse part="continuation">...</verse>
> </role>
> <role name='...'>
>   <verse part="end">...</verse>
>   <verse>...</verse>
>   ...
> </role>
>
> I need to know if a continuation is the only one between beginning and end,
> the first or the second of two, the first, second or third of three, and so
> on.
>
> <xsl:value-of select="count(preceding::verse[@part != 'beginning']) "/> gives
> me the count of all preceding verses with part attribute other
> than "beginning" from the beginning of the piece, what is not what I want.
> I wish to have the count of preceding parts of verse from the last beginning
> part.
>
> Could someone help me?
>
> Thanks in advance,
> Ph. Faehndrich


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