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

[no subject]

From: mbrown@xxxxxxxxxxxxx (Mike Brown)
Date: Thu, 9 Mar 2000 11:59:59 GMT
[no subject]
Regine Vergon wrote:
> my new variable called "x" contains now:
> 
> some text with some tags like <br/>
> this one to go to next line.
> <b> to have bold text</b>
> another bla bla bla 
> <br/>
> 
> If i do:
>    <xsl:copy-of select="substring($x,1,1000)"/>

Here's an explanation of why that won't work.

You have to realize that $x is in this situation a result tree fragment, not a string. The markup <br/> and <b>...</b> are not text in the string and you cannot access them as substrings.

The result tree fragment has this structure (I'll put newlines in as \n):

|__text 'some text with some tags like '
|
|__element 'br'
|
|__text '\nthis one to go to next line.\n'
|
|__element 'b'
|    |__text ' to have bold text'
|
|__text '\nanother bla bla bla\n'
|
|__element 'br'

First, what does substring($x,1,1000) mean?

XPath explains that in this function, $x is expected to be a string, so before the function is evaluated, $x will be converted to a string. Section 11.1 of the XSLT spec and various sections of the XPath spec explain, in a roundabout way, that this string will be the concatenation of the string-values of all text node descendants of the root node in document order. In other words, it will be just the text from the text nodes in the tree -- not the elements.

Second, what does xsl:copy-of select="substring(foo)" mean?

The substring() function returns a string, and Section 11.3 of the XSLT spec, regarding xsl:copy-of, states:

"The required select attribute contains an expression. When the result of evaluating the expression [...] is neither a node-set nor a result tree fragment, the result is converted to a string and then inserted into the result tree, as with xsl:value-of."

I know this doesn't solve your problem, but hopefully it helps you see why this method wasn't working.


 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-2013 All Rights Reserved.