[Top] [All Lists]

Re: [xsl] Selecting unparsed text from inside a tag

2008-03-25 14:35:47

I said I sometimes use xsl:sequence (instead of value-of, copy-of,
apply-templates) and wondered if there might be side effects to using
xsl:sequence for this purpose that I may not know about.... 

If you are going to the result tree then xsl:sequence and xsl:copy-of
are the same thing for that use, but if it is the result of a template
or function being save in a varuiable then they are different, using
copy-of you get new (parentless) nodes that are copies of the original
nodes, using xsl:sequence references the original nodes in the document.
This can make a lot of difference, which you need depends on what you
want to do.

So if the input is
and you do

<xsl:variable name="v1" as="node()*">
  <xsl:copy-of select="x/node()"/>
<xsl:variable name="v2" as="node()*">
  <xsl:sequence select="x/node()"/>

Then if you copy either $v1 or $v2 to the result tree you get

but for example
$v1[1]/following-sibling::* is <b/><c/> as they are the following
siblings of <a/> in the original document but

$v2[1]/following-sibling::* is the empty sequence as $v2 consists of
three new nodes <a/>, <b/>, <c/> with no common parent and unconnected
by the sibling axis.

It would be hard to guess that you meant the content of p in 

<p>Some text and <br/> some more <b>text</b>.</p>

from the subject line as it is parsed and it is not the content of a
tag. An XML parser parses the entire source document before XSLt sees
any of the input, and there are 5 tags in the above with contents
p, br, b, b and p. Element content is marked up _between_ two tags, it
isn't the content of either of them.


The Numerical Algorithms Group Ltd is a company registered in England
and Wales with company number 1249803. The registered office is:
Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom.

This e-mail has been scanned for all viruses by Star. The service is
powered by MessageLabs. 

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>