次のように、XSLT と Saxon を使用して XML を変換しています。
Source sourceXML = new StreamSource(...);
Source sourceXSLT = new StreamSource(...);
System.setProperty("javax.xml.transform.TransformerFactory", "net.sf.saxon.TransformerFactoryImpl");
TransformerFactory transFact = TransformerFactory.newInstance();
Templates cachedXSLT = transFact.newTemplates(sourceXSLT);
Transformer transformer = cachedXSLT.newTransformer();
transformer.setOutputProperty("indent", "no");
transformer.transform(sourceXML, new StreamResult(System.out));
スタイルシートはMapForceを使用して生成され、頻繁に変更されます。変換は一般的に機能しますが、すべての要素の前に名前空間nを付けます。これはおそらく、スタイルシートの次の行によるものです。
<xsl:namespace-alias stylesheet-prefix="n" result-prefix="#default"/>
MapForce ツールはプレビューでこのプレフィックスを表示しないため、トランスフォーマーでこれを変更するのはおそらく非常に簡単です。誰かが私を正しい方向に向けることができますか? または、スタイルシートを取り除くために、スタイルシートで (手動で) 前処理を行う必要がありますか?
スタイルシートの簡素化されたバージョンは次のようになります。
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:n="..." xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:grp="http://www.altova.com/Mapforce/grouping" exclude-result-prefixes="fn grp xs xsi xsl" xmlns="...">
<xsl:namespace-alias stylesheet-prefix="n" result-prefix="#default"/>
<xsl:output method="xml" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
...
</xsl:template>
</xsl:stylesheet>