1. Letting go... (RTF var and string-based test)
2. But a question about use of xsl:for-each re: RTF vars: can I avoid
them?
========================================================================
=====
1. Letting go... (RTF var and string-based test)
========================================================================
=====
Thank you, Michael Kay (and Mike Harmaan as well).
http://www.biglist.com/lists/xsl-list/archives/200305/msg00025.html
http://www.biglist.com/lists/xsl-list/archives/200305/msg00028.html
I agree: nodeset var, and nodeset 'test' is best.
That is how I am now doing it.
(Your suggested code tightened up mine even further, removing the need
for an interim variable. Thanks.)
How To:
- Step 1. Nodeset var: Create the variable as a nodeset 'xsl:variable
select='
[instead of RTF 'build up' <xsl:variable> ... </xsl:variable>],
- Step 2. Nodeset test: Then test with 'nodeset presence' (xsl:when
test="$myvar")
[instead of string-based xsl:when test="not($myvar='')" ]
Good.
-------
But the reason I wrote in was to pursue understanding of a
hypothetical requirement:
- testing an RTF var,
- with a string-based 'test',
- against the (admittedly unusual) data of what
I
call "Empty Element Content Only (NO
Whitespace)" ("EECO-NW")
Example: <markup><img src="pic.gif"/></markup>
I'm going to "let this go...", but here was my thinking:
(Optional Reading!)
That is, _if_ you (for some reason(?)) had to build up an RTF
variable...
[ see perhaps the entry in Michael Kay's book 'XSLT' (xsl:for-each
entry)
on "Changing the Current Node" ],
_then_,
is there a string-based 'test' that would catch the (admittedly unusual)
condition of EECO-NW? e.g. <markup><img src="pic.gif"/></markup>
I think the answer is No.
When I test this against the string-based <xsl:when
test="not($myvar='')"/>,
it does not perform correctly (in my estimation), as it believes
nothing is there (?).
If I introduce even a single space, then it does perform
correctly: <markup> <img src="pic.gif"/></markup>.
[Likewise, another string-based test like
<xsl:when test="not(string-length($myvar)=0)"> does exactly the same.]
== Something Of A Conclusion:
I'm getting the impression that seeing as the nodes created in this
EECO-NW RTF
have no content of string values, this is why no string test will find
anything there.
(And I guess you would only get at the attribute values if you
explicitly
ask for them (XPath ?) ?)
So, I'm going to let that one go... :>)
Again, I'll use nodesets and nodeset testing. Thanks, all.
========================================================================
=====
2. But a question about use of xsl:for-each re: RTF vars: can I avoid
them?===================================================================
==========
The RTF variable "build-up" seems most suited to xsl:for-each use.
Q. What can be said about 'xsl:for-each select=' as compared to
'xsl:variable select='
(or 'xsl:apply-templates select=') ?
That is, setting aside two important concepts xsl:for-each can do for
you
(as delineated in Michael Kay's book 'XSLT'):
1. xsl:sort
2. the use of xsl:for-each to "Change the Current Node"
(yet another thing I would never have thought of (!))
is it reasonable to assert that one can do without the use of
'xsl:for-each select=', and can achieve everything one needs within
the 'select=' attribute of 'xsl:variable' and 'xsl:apply-templates' ?
If this assertion is (reasonably) the case, then I guess I can
(reasonably)
expect to be able to avoid creating variables by way of RTF, and can
make
them instead the preferred way of 'xsl:variable select=' statements.
Yes?
Thanks for any light anyone can shed, etc.
Best regards,
William Reilly
wreilly(_at_)digitas(_dot_)com
Boston, Massachusetts U.S.A.
++++ /End of posting ++++++++++++++++++++++++++++++++++++++++++++++++++
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list