Subject: Re: [xsl] Perplexing Problem in Embedding Stylesheet From: Mike Brown <mike@xxxxxxxx> Date: Wed, 31 Oct 2001 19:10:47 -0700 (MST) |
Sean Kelly wrote: > This worked to some degree, however when I place the <xsl:value-of select> > tags in seperate (and correctly nested) <p></p> tags, the data gets > displayed as one line, and the <b></b> gets ignored so does <i></i> and > linebreaks <br />. !!!!!!! I might be assuming too much, but it appears that what you are thinking of as "the data" is wrong, you aren't understanding what xsl:value-of really does, and as David Carlisle stated, you need to realize that your XPath expressions are relative to the node currently being processed, which changes inside an xsl:for-each vs what it was elsewhere in the template. I'll address the other 2 points. Take this example: <someData><p><i>hello</i> <b>world</b></p></someData> The content of the "someData" element is not a string of character data consisting of "<p><i>hello</i> <b>world</b></p>". Rather, the XML was first parsed into this logical tree: element 'someData' |__element 'p' |__element 'i' | |__Unicode character data 'hello' |__Unicode character data ' ' |__element 'b' |__Unicode character data 'world' Note that the markup - the tags - disappeared. The info was fed to the XSLT processing application, probably as a series of SAX events. The XSLT processor then exposed this info to you using the XPath/XSLT data model, in which everything is addressable as a more useful tree of nodes: element 'someData' w/string-value ('hello'+' '+'world') | |__element 'p' w/string-value ('hello'+' '+'world') | |__element node 'i' w/string-value ('hello') | | | |__text node w/string-value ('hello') | |__text node w/string-value ' ' | |__element node 'b' w/string-value ('world') | |__text node w/string-value ('world') All your XPath and XSLT operations use this tree. In your stylesheet when you say <xsl:value-of select="someData"/> you are essentially directing the XSLT processor to create in the result tree (which will hopefully be serialized when it's finished) a text node with a string-value that is the same as the string-value of all the "someData" element children of the node currently being processed. If you're currently processing the parent node of 'someData', then the value-of will effectively produce the concatenation of the string-values of someData's descendant text nodes (the definition of an element's string-value) -- 'hello world'. If you use xsl:copy-of instead of xsl:value-of, the entire branch(es) of nodes you select will be copied verbatim to the result tree. I believe that's what you really want. - Mike ____________________________________________________________________________ mike j. brown, fourthought.com | xml/xslt: http://skew.org/xml/ denver/boulder, colorado, usa | personal: http://hyperreal.org/~mike/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Perplexing Problem in Emb, David Carlisle | Thread | [xsl] XSL-FO to Pagemaker, Wayne Davis |
RE: [xsl] Question of performance, Chris Bayes | Date | RE: [xsl] Infinite Loop when trying, Ivan Pedruzzi |
Month |