[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: count string-length without white-space and breaki

Subject: Re: count string-length without white-space and breaking if white-spa ceexists after 126 characters
From: "Vasu Chakkera" <vasucv@xxxxxxxxxxx>
Date: Thu, 20 Jun 2002 15:49:43 +0000
count string
Hans ,
The following is your solution
I have considered the following XML..

<row>
<memotext>abcdefghijklmm....</memotext>
<!-- assumption that you have more of the darkonrakt elements and u want to check the memotext text length at every <darkonrakt> node..
-->
<darkonrakt>
</darkontract>
<darkonrakt>
</darkontract>
<darkonrakt>
</darkontract>
</row>


( just added the parent element.. )

the xsl to get the Break if the string length exceeds 126 characters would be:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:for-each select="/row/darkonrakt">
<xsl:choose>
<xsl:when test="string-length(preceding::memotext)&gt;126">
<!-- or <xsl:when test="string-length(../memotext)&gt;126"> -->
<xsl:value-of select="string-length(preceding::memotext)"/>
<br></br>
</xsl:when>
<xsl:otherwise>
no break becoz the length of the memo text is <xsl:value-of select="string-length(preceding::memotext)"/> which is less than 126
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
This code will output a <br></br> and the string length(just for verification )if the string-length of the memotext is greater that 126 ... if it is less , then it outputs a string "no break because the"+ string-length +" is lesser than 126".


Will this serve your purpose???
Vasu

From: "Braumüller, Hans" <h.braumueller@xxxxxxxxxxxx>
Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
To: "'xsl-list@xxxxxxxxxxxxxxxxxxxxxx'" <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Subject: count string-length without white-space and breaking if white-spa ce exists after 126 characters
Date: Thu, 20 Jun 2002 17:04:35 +0200


Hi,

can please anyone indicate me,

First,

why i get the tag <br> in the output

if i have in the xml source

<memotext></memotext>

and my xsl-snippet is:

<xsl:value-of select="substring(../memotext, 1, 126)" />
<xsl:if test="string-length((../memotext) &gt; 126)"> <br /></xsl:if>
<xsl:value-of select="substring(../memotext, 127,
string-length(../memotext))"/>

What i am trying to do is counting the characters of the text-node of
memotext

and if the string-length is greater than 126 i want a <br />
only then.

Now i get always a <br />

Is the string-length counting from the position i call
<xsl:if test="string-length((../memotext) &gt; 126)"> <br /></xsl:if> ?

My XML- snippet:
etc ..
<row>
etc..
<memotext></memotext>

<DARKONTRAKT>
etc ..
<!-- from this level i match to test the value of memotext -->

</DARKONTRAKT>
</row>
etc ..


Second, how can i omit (not counting) the white-space characters by the string-length calculation?

Third, how can i put the <br /> (linebreak) after 126 characters in the
output, when a white-space character occurs ?

Thanks,


Hans Braumüller


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





_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp.


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



Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2011 All Rights Reserved.