xsl-list
[Top] [All Lists]

RE: Dumping a variable

2004-12-05 19:49:48

--- Michael Kay <mike(_at_)saxonica(_dot_)com> wrote:


I have a variable, I'd like to dump the XML contained in that variable
without applying any parsing (debugging purposes).

I assume "dump" means "display" rather than "delete"?

What do you mean by saying that the variable contains XML? In XSLT 1.0 a
variable can contain a node-set, or it can contain a string. In both cases
you can display the value of the variable using 

<xsl:message><xsl:copy-of select="$var"/></xsl:message>

and no parsing will be involved. In fact, there is no way to invoke XML
parsing from standard XSLT, so I don't understand your concern.

Michael Kay
http://www.saxonica.com/

Note that the result of xsl:message differs from implementation to 
implementation. For example,
MSXML silently discards your xsl:message that has no terminate="yes", so this 
solution would work
only if you use it like: 
<xsl:message terminate="yes"><xsl:copy-of select="$var"/></xsl:message>
This thing is stated at
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk/html/xmrefxslmessageelement.asp
:
<<Attributes
terminate 
Specifies whether the transformation should terminate upon executing this 
instruction. This
attribute can have one of two string values: "yes" or "no". When the terminate 
attribute is set to
"yes", the content of the element is displayed as the part of the system-level 
error message, and
the transformation terminates. When it is set to "no", the transformation 
proceeds, ignoring the
error message. The default value is "no". >>

Another solution: dump your variable in the output file (if you output XML, not 
text):
<variable-dump name="$var1"><xsl:copy-of select="$var1"/></variable-dump>
...
<variable-dump name="$var2"><xsl:copy-of select="$var2"/></variable-dump>

so later you can look into the output file and look for variable-dump elements.
I recomend you to use this method conditionally: set a parameter of your XSLT 
file (i.e.: debug)
and use like this:
<xsl:if test="$debug">
  <variable-dump name="$var1"><xsl:copy-of select="$var1"/></variable-dump>
</xsl:if>
This way, you can switch easily between debug mode and production mode.



=====
Marian
http://www.utdallas.edu/~mgo031000/


        
                
__________________________________ 
Do you Yahoo!? 
Yahoo! Mail - You care about security. So do we. 
http://promotions.yahoo.com/new_mail

--~------------------------------------------------------------------
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>
--~--



<Prev in Thread] Current Thread [Next in Thread>