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(_at_)digitas(_dot_)com
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