I have an XSL script (I can show it here if necessary) which output an XML file. The problem is that I have this kind of result with SAXON:
<docGenWidget name="ActiveArea">
<param name="WidgetType"
change="D"
fieldDefn="identifierWidgetType_identifier_param">
<identifierType constantValue="A661_ACTIVE_AREA"/>
</param>
<param name="WidgetIdent" change="D" fieldDefn="WidgetIdent_const"/>
<param name="ParentIdent" change="D" fieldDefn="ParentIdent_const"/>
<param name="Enable" change="DR" fieldDefn="EnableWithValidation_param"/>
<param name="Visible" change="DR" fieldDefn="Visible_param"/>
<param name="PosX" change="DR" fieldDefn="PosX_param"/>
<param name="PosY" change="DR" fieldDefn="PosY_param"/>
<param name="SizeX" change="DR" fieldDefn="SizeX_param"/>
<param name="SizeY" change="DR" fieldDefn="SizeY_param"/>
<param name="StyleSet" change="DR" fieldDefn="StyleSet_param"/>
<param name="NextFocusedWidget"
change="DR"
fieldDefn="NextFocusWidgetId_param"/>
<param name="AutomaticFocusMotion"
change="DR"
fieldDefn="AutomaticFocusMotion_param"/>
<padding24Bit/>
<param name="EntryValidation" change="R" fieldDefn="EntryValidation_param"/>
<operation name="PosX_PosY" fieldDefn="PosXY_operation"/>
<operation name="SizeX_SizeY" fieldDefn="SizeXY_operation"/>
<event name="SelectionNoData">
<param name="EventIdent"
fieldDefn="identifierProtocolEventType_identifier_param">
<identifierType constantValue="A661_EVT_SELECTION"/>
</param>
<padding16Bit/>
</event>
</docGenWidget>
As you see, for some of the nodes all the attributes are outputted on the same line, but for some others it is not the case. I would like to have all the attributes in the same line for a node.
The way the XSL works is rather simple in this case, and the input here is:
<widgetDefn name="ActiveArea" widgetTypeId="A661_ACTIVE_AREA" xsi:schemaLocation="http://www.aviation-ia.com/aeec/SupportFiles/schema-6/widgetDefn.xsd file:///C:/ARINC661_ShortcutToSchemaRoot/Permanent/widgetDefn.xsd">
<description>The Active Area widget is a transparent rectangular area defining an Interactive Area. Selection of this area will send an event to the owner application.</description>
<params>
<WidgetIdent_const name="WidgetIdent" />
<ParentIdent_const name="ParentIdent" />
<EnableWithValidation_param name="Enable" mod="DR" />
<Visible_param name="Visible" mod="DR" />
<PosX_param name="PosX" mod="DR" />
<PosY_param name="PosY" mod="DR" />
<SizeX_param name="SizeX" mod="DR" />
<SizeY_param name="SizeY" mod="DR" />
<StyleSet_param name="StyleSet" mod="DR" />
<NextFocusWidgetId_param name="NextFocusedWidget" mod="DR" />
<AutomaticFocusMotion_param name="AutomaticFocusMotion" mod="DR" />
<padding24Bit />
<EntryValidation_param name="EntryValidation" mod="R" />
</params>
<operations>
<PosXY_operation name="PosX_PosY" />
<SizeXY_operation name="SizeX_SizeY" />
</operations>
<raisesEvents>
<eventRef eventName="SelectionNoData" />
</raisesEvents>
</widgetDefn>
With every attribute aligned as I would like.
The way I am calling SAXON here is:
try {
TransformerFactory factory = TransformerFactory.newInstance("net.sf.saxon.jaxp.SaxonTransformerFactory", Thread.currentThread().getContextClassLoader());
Transformer transformer = factory.newTransformer(new StreamSource(xslFile));
if (xlstParamsType == XLSTParametersOptionType.SOURCE_AND_XSD_PATHS) {
transformer.setParameter("source-uri", inputFile.toURI().toString());
transformer.setParameter("xsl-uri", xslFile.toURI().toString());
}
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
transformer.setOutputProperty(OutputKeys.METHOD, "xml");
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
transformer.setURIResolver(resolver);
DocumentBuilderFactory dFactory = DocumentBuilderFactory.newInstance();
dFactory.setNamespaceAware(true);
dFactory.setXIncludeAware(true);
DocumentBuilder dBuilder = dFactory.newDocumentBuilder();
InputSource xslInputSource = new InputSource(new FileInputStream(inputFile));
xslInputSource.setSystemId(inputFile.toURI().toString());
Document xslDoc = dBuilder.parse(xslInputSource);
DOMSource xslDomSource = new DOMSource(xslDoc);
transformer.transform(xslDomSource, new StreamResult(new FileOutputStream(outputFile)));
}
} catch (TransformerConfigurationException | FileNotFoundException ex) {
} catch (TransformerException | SAXException | IOException | ParserConfigurationException ex) {
}
Is the fact the some attributes are not on the same line as the others for some nodes due to the XSL script, or due to an option I forgot to include in my SAXON processor?
Indentation isn't defined in detail in the spec, so each processor does the best it can to make the output easy for humans to read, and of course that's subjective. But very long lines, requiring horizontal scrolling, are generally a bad idea for readability, so Saxon wraps them to show each attribute on a new line.
With Saxon-PE and higher you can control the threshold at which this happens using the serialization property saxon:line-length
.