0

I want to pass the parameter from java application for the indent attribute as below.

I can pass it from java code without any issue but defining the parameter in xslt is an issue. I did the sample below:

<xsl:param select="'yes'">

<xsl:output method="xml" encoding="UTF-8" omit-xml-declaration="yes" indent="{$indent}" />

But when I use like above I am getting the error saying the way I defined the attribute indent is invalid. Please help me to resolve this issue.

1

1 Answer 1

2

The declaration of the parameter with <xsl:param name="indent" select="'yes'"/> is correct but not all attributes of all elements allow an attribute value template. If we look at http://www.w3.org/TR/xslt20/#serialization then we see that those attributes don't allow an attribute value template as otherwise the syntax would say e.g. indent={yes|no}.

If you want to define the indentation in your Java code then check the API of your XSLT processor, it probably has a method to set output serialization settings.

Based on your comment, you are using IBM's Websphere XSLT 2.0 API, I don't have experience using that API so the following is an attempt to try to read the API online documentation to suggest a possible approach to serialize with your custom settings:

XOutputParameters params = yourXSLTExecutableInstance.getOutputParameters();
params.setIndent(true);

List<XItemView> result = yourXSLTExecutableInstance.executeToList(yourJAXPInputSource);
result.get(0).exportItem(yourJAXPStreamResult, params);

That's roughly what I would try, I don't have any access to the API to test.

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

4 Comments

For javax.xml.transform.Transformer the API you're looking for is setOutputProperty(OutputKeys.INDENT, "yes")
Ian we are using IBM API for this transformation. We use XSLTExecutable.execute() for the transformation. We could not see any API to set the INDENT through the java program. If you have any idea please share with me.
@K.Senthuran, I have read through the online doc of the IBM API and tried to find a way to use custom output parameters, see my edited answer. Please note that the code is meant as a suggestion as to which interfaces and methods could help, I have no way of testing that so you will have to do that yourself and probably need to adapt the suggestion.
@ Martin, Your solution helped us to resolve the issue. It is working as expected. Thanks a lot.

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.