0
我正在使用Apache Xalan 2.7.1進行XSLT轉換。XSLT轉換不適用於XALAN
我正試圖將以下input
轉換爲expected-output
。
輸入
<customer>
<customer-name>Diecast Collectables</customer-name>
<phone xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<city>Boston</city>
</customer>
XSLT
<xsl:template match="node()[@xsi:nil = 'true']">
<xsl:copy>NULL</xsl:copy>
</xsl:template>
預期輸出(注意 'NULL' 的值)
<customer>
<customer-name>Diecast Collectables</customer-name>
<phone xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">NULL</phone>
<city>Boston</city>
</customer>
但是這是我用Xalan java庫得到的輸出。(注意有沒有 'NULL' 值)
<customer>
<customer-name>Diecast Collectables</customer-name>
<phone xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"></phone>
<city>Boston</city>
</customer>
但出乎意料的是,上面的XSLT給出預期this online tool輸出。
有人可以請解釋這種差異的原因是什麼?
感謝, Bhathiya
[編輯]
Transfromation代碼
public void transform() throws Exception {
OMElement omElemHeader = AXIOMUtil.stringToOM("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" +
" <customer>\n" +
" <customer-name>Diecast Collectables</customer-name>\n" +
" <contact-last-name>Franco</contact-last-name>\n" +
" <phone xsi:nil=\"true\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"/>\n" +
" <city>Boston</city>\n" +
" </customer>\n");
TransformerFactory tFactory = TransformerFactory.newInstance();
File xslt = new File("/data/xslt.xslt");
Transformer transformer = tFactory.newTransformer(
new StreamSource(new FileInputStream(xslt)));
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
Source xmlSource = new OMSource(omElemHeader);
transformer.transform(xmlSource, new StreamResult(outputStream));
ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
XMLStreamReader reader2 = XMLInputFactory.newInstance().
createXMLStreamReader(inputStream);
StAXOMBuilder builder2 = new StAXOMBuilder(reader2);
OMElement out = builder2.getDocumentElement();
System.out.println(out);
}
看看這個(http://xsltransform.net/nbUY4kv/1)。它使用Xalan 2.7.1。它輸出沒問題。 –
喬爾,這個鏈接不起作用。 – Bee
似乎該網站已關閉。 –