XML修正名前空間宣言
-
20-09-2019 - |
質問
私はこののバグでnoreferrer"> /
解決 2 ただ、完全を期すために: Javaコードます: スタイルシートます: XSLTと彼のヘルプのマッズ・ハンセンに感謝します。Document d = out.outputW3CDom(converted);
DOMSource oldDocument = new DOMSource(d);
DOMResult newDocument = new DOMResult();
TransformerFactory tf = TransformerFactory.newInstance();
StreamSource xsltsource = new StreamSource(
getStream(MEDIA_RSS_TRANSFORM_XSL));
Transformer transformer = tf.newTransformer(xsltsource);
transformer.transform(oldDocument, newDocument);
private InputStream getStream(String fileName) {
InputStream xslStream = Thread.currentThread().getContextClassLoader()
.getResourceAsStream("/" + fileName);
if (xslStream == null) {
xslStream = Thread.currentThread().getContextClassLoader() .getResourceAsStream(fileName);
}
return xslStream;
}
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!--identity transform that will copy matched node/attribute to the output and apply templates for it's children and attached attributes-->
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="@*|*|text()" />
</xsl:copy>
</xsl:template>
<!--Specialized template to match on elements with the incorrect namespace and generate a new element-->
<xsl:template match="//*[namespace-uri()='http://search.yahoo.com/mrss']">
<xsl:element name="{local-name()}" namespace="http://search.yahoo.com/mrss/" >
<xsl:apply-templates select="@*|*|text()" />
</xsl:element>
</xsl:template>
</xsl:stylesheet>
他のヒント
あなたは、おそらくこのようなルールで、XSLTでそれを行うことができます
<xsl:template match="media:*">
<xsl:element name="local-name()" namespace="http://search.yahoo.com/mrss/">
<xsl:apply-templates match="node()|@*"/>
</xsl:element>
</xsl:template>
メディアは、 " http://search.yahoo.com/mrssする" にバインドされています。
私は、コンパイラの助けなしにこれを書いているように、構文を少し微調整する必要があります。また、何を買ってあげることは、おそらく非常にきれいに(多くの要素の名前空間宣言)フォーマットされていないが、それはlocically正しいはずます。