I need to extract root element name attribute my input is as below
<?xml version = '1.0' encoding = 'UTF-8'?>
<xsd:schema xmlns:xsd="http://ift.tt/tphNwY" elementFormDefault="qualified" xmlns:nxsd="http://ift.tt/L8WCuC" nxsd:encoding="US-ASCII">
<xsd:element name="car">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="wheel" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:annotation>
<xsd:appinfo>NXSDSAMPLE=</xsd:appinfo>
<xsd:appinfo>USEHEADER=false</xsd:appinfo>
</xsd:annotation>
</xsd:schema>
The XSL looks like below
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://ift.tt/tCZ8VR" version="2.0">
<xsl:template match="/*/*[local-name()='element']">
<xsl:value-of select="@name"></xsl:value-of>
</xsl:template>
</xsl:stylesheet>
The required output is only "car" but the transformation is generating
NXSDSAMPLE=
USEHEADER=false
car
My program looks like below
Document document;
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
StringWriter sw = new StringWriter();
File rootNameStyleSheet = new File("RootElementNameExtractor.xsl");
File datafile = new File("cf1.xsd");
try {
DocumentBuilder builder = factory.newDocumentBuilder();
document = builder.parse(datafile);
TransformerFactory tFactory = TransformerFactory.newInstance();
StreamSource stylesource = new StreamSource(rootNameStyleSheet);
Transformer transformer = tFactory.newTransformer(stylesource);
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
transformer.setOutputProperty(OutputKeys.INDENT, indent);
DOMSource source = new DOMSource(document);
StreamResult result = new StreamResult(sw);
transformer.transform(source, result);
}
Any inputs on what is wrong with XSL would be helpful
Aucun commentaire:
Enregistrer un commentaire