Subject: RE: [xsl] xsl:copy-of O.K. on RTF, but nothing on <EMPTY/> element content (?) From: "William Reilly" <wreilly@xxxxxxxxxxx> Date: Wed, 23 Apr 2003 17:30:01 -0400 |
My basic question: (follow-on to my yesterday e-mail) >> What is the difference in these two bits of markup, from the point of the XSLT processor, working on an <xsl:apply-templates> or an <xsl:copy-of> instruction? << +++++++++++++++++++++++++++++++++++++++++++ CODE #1: <markup> <img src="pic.gif"/></markup> << RTF +++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++++++++++++ CODE #2: <markup><img src="pic.gif"/></markup> << nodeset (I believe(?)) +++++++++++++++++++++++++++++++++++++++++++ - KEYSTROKES The simple difference in keystrokes is one has a space between elements ((#1) <markup> <img>), the other doesn't ((#2) <markup><img>). - TREE of NODES The difference in the tree of nodes visited by the XSLT processor (as revealed by CraneSoftwrights "showtree.xsl") is shown further below. (Essentially, one (#1) has an extra "Text" node). http://www.cranesoftwrights.com/resources/showtree/showtree-20000610.xsl - DOES IT WORK? The difference in getting results to process through <xsl:apply-templates> and <xsl:copy-of> is that: - GOOD: one works! (the one _with_ the space (#1)), - NOT GOOD: and the other does _not_! (#2)(I get "empty node list" - both Xalan and Saxon). - RTF vs. NODESET (???) >> But there's something about the XSLT processor's behavior with "Result Tree Fragments" (RTF) ((#1) the one _with_ the space) vs. "nodesets" ((#2) the one without (I think )) that I fail to grasp, and which I'd like to have a little better understanding of. CONTEXT: This e-mail is follow-on to my earlier, which has more context. It also has the XML & XSLT code SNIPPETS: http://www.biglist.com/lists/xsl-list/archives/200304/msg01075.html PROBLEM DESCRIPTION... - I'm building up an xsl:variable (Result Tree Fragment (RTF)), - by means of doing a simple 'document()' lookup, - running an 'xsl:for-each' selection over in the lookup file, - and then an 'xsl:copy-of' (or xsl:apply-templates) to my result file of the selected content I want from over there: - namely, what's between one set of the <markup> tags. HEAD BANGING, or, HOW ABOUT A DIFFERENT XML MODEL? To try to break out of this problem, I've tried modelling the <img> information a couple of different ways (and creating appropriate templates to process): CODE: <markup><image><filename>pic.gif</filename><alternative>Describe image with this text</alternative></image></markup> CODE: <markup><image filename="pic.gif"><alternative>Describe image with this text</alternative></image></markup> CODE: <markup><image filename="pic.gif">Describe image with this text</image></markup> >> Alas, same issue every time: if I don't insert a space between elements, I still get no results. If I do insert a single space, I get everything I need. (You'd think by now I'd have given up 8>) Thanks again for any insights anyone can offer. William Reilly wreilly@xxxxxxxxxxx Boston, Massachusetts U.S.A. ================== 1. YES. DOES WORK (xsl:copy-of or xsl:apply-templates can be made to work) +++++++++++++++++++++++++++++++++++++++++++ CODE #1: <markup> <img src="pic.gif"/></markup> << RTF +++++++++++++++++++++++++++++++++++++++++++ Discussion: YES, there's whitespace: a single space (that's all you need to turn this into a Result Tree Fragment (RTF) apparently!) Question: Now that it's an RTF, what is it about RTFs that the <xsl:apply-templates/> _does_ get the <xsl:template match="img"> to process successfully?? --- showtree --- SEE ITEM 18 -------- 2.4.4.2.17 Text (msgs-file,msgs,msg,segment): { } 2.4.4.2.18 Element 'markup' (msgs-file,msgs,msg,segment): 2.4.4.2.18.1 Text (msgs-file,msgs,msg,segment,markup): { } 2.4.4.2.18.2 Element 'img' (msgs-file,msgs,msg,segment,markup): 2.4.4.2.18.2.A Attribute 'src': {pic.gif} 2.4.4.2.19 Text (msgs-file,msgs,msg,segment): { } ------------------------ ================== 2. NO. DOES _NOT_ WORK (xsl:copy-of or xsl:apply-templates can NOT be made to work -- it's an EMPTY NODE LIST) +++++++++++++++++++++++++++++++++++++++++++ CODE #2: <markup><img src="pic.gif"/></markup> << nodeset (I believe(?)) +++++++++++++++++++++++++++++++++++++++++++ Discussion: NO whitespace. EMPTY element content only. Question: Is this a "nodeset" (as opposed to Result Tree Fragment (RTF))? >> KEY QUESTION: Whatever it is, why doesn't <xsl:apply-templates/> get the template I have for <xsl:template match="img"> to get processed?? --- showtree --- SEE ITEM 12 -------- 2.4.6.2.11 Text (msgs-file,msgs,msg,segment): { } 2.4.6.2.12 Element 'markup' (msgs-file,msgs,msg,segment): 2.4.6.2.12.1 Element 'img' (msgs-file,msgs,msg,segment,markup): 2.4.6.2.12.1.A Attribute 'src': {pic.gif} 2.4.6.2.13 Text (msgs-file,msgs,msg,segment): { } ------------------------ ++++ /END of e-mail ++++++++++++++++++++++++++++++++++++++++++++++++++ --- ORIGINAL E-Mail --------------------------- Date: Tue, 22 Apr 2003 22:10:48 -0400 From: "William Reilly" <wreilly@xxxxxxxxxxx> Subject: [xsl] xsl:copy-of O.K. on RTF, but nothing on <EMPTY/> element content (?) Greetings. With this e-mail I'm looking to confirm if I am barking up the wrong tree. Can this be done? Ought I to be trying a different approach? Maybe to modelling my XML (?), maybe to programming my XSLT (??) Thank you for any help or clarification that can be offered. William Reilly wreilly@xxxxxxxxxxx Boston, Massachusetts U.S.A. =============== Below are 3 snippets: - - XML Main Data File - - XML Lookup File - - XSLT That Does document() Lookup PROBLEM DESCRIPTION... - - I'm building up an xsl:variable (Result Tree Fragment (RTF)), - by means of doing a simple 'document()' lookup, - running an 'xsl:for-each' selection over in the lookup file, - and then an 'xsl:copy-of' to my result file of the selected content I want from over there: - (namely, what's between one set of the <markup> tags. Pls. see below). ++ CASE # 1 (WORKING FINE) Here, what's found is a RTF: <markup>'s content can have either Mixed Content, or be simply #PCDATA. 'xsl:copy-of' copies it all over, just fine. <markup>an <a href="http://www.bank.com/CALIF/interest.html">Interest Maximizer account</a>.</markup> ++ CASE # 2 (NOT WORKING) Here, what's found is apparently _not_ a RTF (?), but instead a nodeset (??). This content is EMPTY ELEMENT ONLY. (Not even any whitespace.) At any rate, xsl:copy-of gets no result back ("empty node list") (tried both Xalan and Saxon). <markup><img src="images/california_header.gif"/></markup> ++ CASE # 2a (This WILL Work) Interestingly, here, if I introduce even a single space (!) between <markup> and <img>, it then works fine (becomes Mixed Content). <markup> <img src="images/california_header.gif"/></markup> - -=- A Few Words from the Recommendation... -=-=-=-=-=-=-=-=-= http://www.w3.org/TR/xslt#copy-of 11.3 Using Values of Variables and Parameters with xsl:copy-of "...used to insert a result tree fragment" "...(for) a node-set, all the nodes in the set are copied" "The xsl:copy-of element can be used to insert a result tree fragment into the result tree, without first converting it to a string as xsl:value-of does... When the result of evaluating the expression is a result tree fragment, the complete fragment is copied into the result tree. When the result is a node-set, all the nodes in the set are copied in document order into the result tree; copying an element node copies the attribute nodes, ... " - -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- http://www.w3.org/TR/xslt#copying 7.5 Copying "The xsl:copy element provides an easy way of copying the current node." - -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- =-=- Conclusions, Thoughts, Wonderings... (?) =-=-=-=-=-=-=-=-= Hmmmm. I don't truly understand everything about result tree fragments and nodesets, but I am puzzled why the <img src="pic.gif"/> empty element can't get successfully "xsl:copy-of'd" out of its position as the only node found inside a container element 'markup'. ? Odd, to me. Doesn't it say (above) in the Recommendation that "nodes in the set are copied..." and "copying an element node copies the attribute nodes" ?? Aside: As for xsl:copy, I don't believe it fits the bill here, as I'm relying on xsl:copy-of's "select" attribute to help me 1) pick the right <markup> tag, then 2) copy it over right then and there. xsl:copy seems more suited to when you already have selected the node you want; I'm not in that situation (to the best of my understanding (!?)). As I say, I'd be interested to hear useful learnings on why this is not working. In the meantime, I may just work on another approach to providing a container for the <img> tags markup I need. THANKS! William Reilly P.S. Also, for what it's worth, I just tried removing the document() lookup from the equation by putting both XML files into one, and got identical results. It's really an xsl:copy-of issue. ++++++++++++++++++++++++++ 3 FILE SNIPPETS ++++++++++++++++++++++++++ ====================== XML Main Data File: ("lookup" is triggered on <main-msg> element) - ---------------------- <td>some text <main-msg name="which-product"/> some more text</td> <td><main-msg name="header-image"/></td> - ---------------------- ====================== XML Lookup File: (2 example 'msg's: which-product, and header-image) - ---------------------- <msgs> <msg name="which-product"> <segment name="CALIFORNIA"> <markup>an <a href="http://www.bank.com/CALIF/interest.html">Interest Maximizer account</a>.</markup> </segment> <segment name="OREGON"> <markup>a <a href="http://www.bank.com/OREGON/money.html">Money Maximizer account</a>, with no monthly fee.*</markup> </segment> <segment> ... </segment> </msg> <msg name="header-image"> <segment name="CALIFORNIA"> <markup><img src="images/california_header.gif"/></markup> </segment> <segment name="OREGON"> <markup><img src="images/oregon_header.gif"/></markup> </segment> <segment> ... </segment> </msg> ... </msgs> - ---------------------- ====================== XSLT That Does document() Lookup: - ---------------------- <xsl:param name="segment" select="CALIFORNIA"/> ... <xsl:template match="main-msg"> <xsl:variable name="msg-name" select="@name"/> <xsl:variable name="msg-fill-contents"> <xsl:for-each select="document($LookupFilename)//msgs/msg"> <!-- XSL:COPY-OF Works fine EXCEPT when <markup> contains EMPTY ELEMENT ONLY content. e.g. <markup><img src="images/california_header.gif"/></markup> (Note: I tried both with and without final '/node()' step.) ================================================================== --> <xsl:copy-of select="segment/markup[ancestor::msg/@name=$msg-name and ancestor::segment/@name=$segment]/node()"/> <!-- /================================================================== --> </xsl:for-each> </xsl:variable> ... (use the $msg-fill-contents variable)... </xsl:template> - ---------------------- ++++++ /END of e-mail +++++++++++++++++++++++++++++++++++++++++++ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list ------------------------------ End of XSL-List Digest V4 #1259 ******************************* XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] xsl:copy-of O.K. on RTF, but , William Reilly | Thread | [xsl] Re: CDATA output, Nathan Shaw |
RE: [xsl] Re: Grouping problem?, Benjamin Farrow | Date | RE: [xsl] Confounded by grand-paren, Rick Taylor |
Month |