我有一个输出XML文件的XSL脚本(如果需要,我可以在这里显示它)。
<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>
如您所见,对于某些节点,所有属性都输出在同一行,但对于其他一些节点,情况并非如此。我希望将节点的所有属性都输出在同一行。
XSL在本例中的工作方式相当简单,这里的输入为:
<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>
所有的属性都按我的意愿排列。
我在这里调用SAXON的方法是:
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) {
}
对于某些节点,某些属性与其他属性不在同一行上,这是由于XSL脚本,还是由于我忘记在SAXON处理器中包含某个选项?
1条答案
按热度按时间nfeuvbwi1#
缩进在规范中没有详细定义,所以每个处理器都尽其所能使输出易于阅读,当然这是主观的,但是非常长的行需要水平滚动,这通常对可读性来说是个坏主意,所以Saxon将它们 Package 起来,在新的一行上显示每个属性。
在Saxon-PE和更高版本中,您可以使用序列化属性
saxon:line-length
控制发生这种情况的阈值。