This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: Truncating output of a node


Hi Wendell and Mike,

Thanks for the responses.

At 10:35 AM 4/19/01, Mike wrote:
> > I am trying to output the first n sentences of a node. I have
> > tried using
> > for-each with a conditional to stop output but have had no luck.
> >
> > Given the following XML fragment, what is the best way to
> > output only the
> > first n sentences? Note that the node has both text and child nodes.
> >
>Write a recursive template that takes the text and n as parameters; in this
>template,
>if n>0, output the first sentence (using substring-before), then make a
>recursive call on the the same template, passing the remaining text (using
>substring-after) and n-1 as the parameters.

I understand the suggestion to use a recursive template to filter
the output. The problem I was having was that the sentences can
contain the <span> tags. It seems to me that the fragments that
are being processed are sometimes text and sometimes the child
tags. I guess I'm confused how the pieces an element are processed
when it has tags mixed with text.


On Thursday, April 19, 2001 6:57 AM, Wendell wrote:

>This will work assuming you have identified some dependable way to delimit 
>sentences in your data. You might assume that the presence of a character 
>"." will indicate the end of a sentence.

Your are right it would normally be difficult but the content is technical
and doesn't usually contain other types of punctuation such as ? and !. I
was thinking of using '. ' as the delimiter. If I happen to get an extra
sentence because of other punctuation it is not a problem. This template is
being used to create a short summary of a piece of a doecument. Also, the
<span> tags don't cross sentence boundaries so that huge mess is avoided.

I guess another possibility it to output n characters and add '...' at the
end to create the summary. Is that any easier?

Thanks for your help,
Jim

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]