xsl-list
[Top] [All Lists]

Re: [xsl] Applying Templates Up To The Node That Contains The nth Descendant Character

2008-12-23 03:23:25
I thought of following (a 2.0 solution).

<xsl:template match="body">
  <body>
    <xsl:apply-templates select="p[1]" />
  </body>
</xsl:template>

<xsl:template match="p">
  <xsl:variable name="x"
select="string-length(string-join(preceding-sibling::p, ''))" />
  <xsl:variable name="y" select="string-length(.)" />
  <xsl:if test="$x &lt; 1000">
    <xsl:copy-of select="." />
  </xsl:if>
  <xsl:if test="($x + $y) &lt; 1000">
    <xsl:apply-templates select="following-sibling::p[1]" />
  </xsl:if>
</xsl:template>

This is not tested.

On Tue, Dec 23, 2008 at 11:58 AM, Jeff Sese 
<jeferson(_dot_)sese(_at_)asiatype(_dot_)com> wrote:
Hi,

I have a book structure mark-up and I'm trying to get an extract of the book
contents to represent a preview. However, I only want to get the contents
upto the node that contains the nth descendant character of the book body.
How can I do this?

I have:
<book>
       <body>
               <p>some text</p>
               <p>some text</p>
               ...
               <p>some text, here is the 1,000th character, some more
text</p>
               <p>some text</p>
       </body>
</book>

I want my output to be all the descendant::p of body but only upto the p
that contains the 1000th character.

Thanks in advance,

-- Jeff



-- 
Regards,
Mukul Gandhi

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--