2

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>

With 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.

3
  • Are you sure it is not working ? If you are looking the results through a browser the tags will not display .. except in the source code.. Commented Jan 25, 2010 at 18:22
  • Positive. I probably should have given context when I posted. I'm testing an application via JBoss so viewing through the server.log in the putty output window any xsl:message output. This is what I get currently... 2010-01-25 18:05:41,865 ERROR [STDERR] file:///jboss-3.2.0/bin/javax.xml.transform.dom.DOMSource; Line 0; Column 0; Contents of the nodeset_statuses:- 11001223400010334000103The order is already on an ASNthe order is already on an ASN151001223400010301/22/2010 00:00:00 GMT340001031499Automatic rejectionR0201R1308M340C Commented Jan 26, 2010 at 9:29
  • So basically I need structure of the xml to understand what the values relate to. I don't currently know what the variable contains as far as XML structure so I can't work out the mappings even if I could comma separate them. Commented Jan 26, 2010 at 9:30

2 Answers 2

1

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).

Sign up to request clarification or add additional context in comments.

Comments

0

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.