[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]


From: mbrown@xxxxxxxxxxxxx (Mike Brown)
Date: Thu, 9 Mar 2000 11:59:59 GMT

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
Keywords