Debugging by outputting the full XML of a variable in xslt using xml:message
I have a variable called $statuses
.
I want to output the full XML, rather than just the values in the nodes, so I tried to do the following:-
<xsl:message>Contents of the nodeset_statuses:-
<xsl:copy-of select="$statuses"/>
</xsl:message>
However, this only outputs the values in the nodes in the XML which is not what I want. I want the XML "as it is". I've seen some examples of "prettyPrint" templates like with dom4j but I'll be honest it really shouldn't be that much work.
Is there any Java method call available?
I tried something like:
<xsl:message>
<xsl:variable name="output" select="java:System.out.println('print me something')"/>
</xsl:message>
Wit开发者_运维技巧h an XML namespace definition of:
xmlns:java="http://xml.apache.org/xslt/java"
But that didn't work as it returned the error:
System.out.println isn't a recognised part of the java / xslt apache extensions.
Does anyone know what the actual Java call is to achieve what I want or a way to do it?
Thanks in advance.
Your comment suggests you're using Xalan, which has an extension for writing output to different result documents. Add
xmlns:redirect="http://xml.apache.org/xalan/redirect"
extension-element-prefixes="redirect"
to the <xsl:stylesheet>
root element of your transformation, then you can use
<redirect:write select="'statuses_debug.xml'">
<statuses>
<xsl:copy-of select="$statuses"/>
</statuses>
</redirect:write>
to dump the variable to a separate file (I've added a single root element to make the output well-formed if $statuses
contains more than one element).
Use the document function and the xsl:variable
nodeset to read the value:
<xsl:message>
<xsl:value-of select="document('')/*/xsl:variable/@select[../@name='output']"/>
</xsl:message>
精彩评论