Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - XPath >Thread Next - Re: XPath Re: XPathTo: NULL Date: 11/3/2004 10:55:00 AM Hi, Wow, and you want that in one XPath expression? Assuming the current context node (or text node thereof) is the sentence and that $break is the desired position (e.g. 300) something like... concat(substring(.,1,$break), substring-before(substring(.,$break+1,string-length(.) * not(substring(.,$break,1) = '.') ),'.'), substring(.,$break+1,string-length(.) * not(contains(substring(.,$break+1),'.'))), substring('.',1,1 * (not(substring(.,$break,1) = '.') or not(contains(.,'.'))))) Heh, it ain't pretty but it works (i think???)! ;) Some test code... XML <root> <!-- 1234567890123456789012345678901234567890123456789012345678901234567890123456 7890123456 --> <sentence>dshjsd sjhhjds sdjsj sj. sdjhh sjsjd sjjhsdh. sjsjhd sjjshhd sjhdsjh sjhjd.</sentence> <sentence>kds skj swiuui weiuuiew ewiuiew ewiuwieuiiuwe weiiuewui ewiiuewiu weiiuewi</sentence> <sentence>weoio ksjdkj skdskjjk woewoi weoiew weiooiew ew. wepoopew ewpopoew weoppoewo</sentence> <sentence>kjdkjds sdkjweiu iwuew wiewiu. oweio ewowpwe wiiwue woiwie. wppwepoew wiuwei.</sentence> </root> XSL <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text"/> <xsl:variable name="break" select="30"/> <xsl:template match="/"> <!-- list original and spliced strings... --> <xsl:text> 123456789012345678901234567890 </xsl:text> <xsl:for-each select="root/sentence"> <xsl:text>old:- "</xsl:text> <xsl:value-of select="."/> <xsl:text>" new:- "</xsl:text> <xsl:value-of select="concat(substring(.,1,$break), substring-before(substring(.,$break+1,string-length(.) * not(substring(.,$break,1) = '.') ),'.'), substring(.,$break+1,string-length(.) * not(contains(substring(.,$break+1),'.'))), substring('.',1,1 * (not(substring(.,$break,1) = '.') or not(contains(.,'.')))))"/> <xsl:text>" </xsl:text> </xsl:for-each> <xsl:text> </xsl:text> <!-- find the maximum length of those... --> <xsl:variable name="max-length"> <xsl:for-each select="root/sentence"> <xsl:sort select="string-length(concat(substring(.,1,$break), substring-before(substring(.,$break+1,string-length(.) * not(substring(.,$break,1) = '.') ),'.'), substring(.,$break+1,string-length(.) * not(contains(substring(.,$break+1),'.'))), substring('.',1,1 * (not(substring(.,$break,1) = '.') or not(contains(.,'.'))))))" data-type="number" order="descending"/> <xsl:if test="position() = 1"> <xsl:value-of select="string-length(concat(substring(.,1,$break), substring-before(substring(.,$break+1,string-length(.) * not(substring(.,$break,1) = '.') ),'.'), substring(.,$break+1,string-length(.) * not(contains(substring(.,$break+1),'.'))), substring('.',1,1 * (not(substring(.,$break,1) = '.') or not(contains(.,'.'))))))"/> </xsl:if> </xsl:for-each> </xsl:variable> <xsl:text>The longest string is </xsl:text> <xsl:value-of select="$max-length"/> <xsl:text> chars long</xsl:text> </xsl:template> </xsl:stylesheet> Cheers Marrow http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger) http://www.topxml.com/Xselerator "js" <anonymous@d...> wrote in message news:e1ldXqTwEHA.4048@T...... > Hi, > > I am trying to use XPath to extract substring of a text node. The > substring should be at least 300 characters long. If the 300th character > is in the middle of a sentence, the substring should include the > complete sentence which the 300th character resides. I use XPath > function substring($outputContent,1,$displayLength). What function or > XPath syntax will allow me to find the period of the ending sentence so > that I can dynamically adjust the $displayLength variable? Thanks. > > > *** Sent via Developersdex http://www.developersdex.com *** > Don't just participate in USENET...get rewarded for it! | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
