Cra*_*ker 10 xml xslt namespaces
我有一个带有非命名空间元素的XML文档,我想使用XSLT向它们添加命名空间.大多数元素都在命名空间A中; 一些将在命名空间B中.我该怎么做?
and*_*otn 13
用foo.xml
<foo x="1">
<bar y="2">
<baz z="3"/>
</bar>
<a-special-element n="8"/>
</foo>
Run Code Online (Sandbox Code Playgroud)
和foo.xsl
<xsl:template match="*">
<xsl:element name="{local-name()}" namespace="A" >
<xsl:copy-of select="attribute::*"/>
<xsl:apply-templates />
</xsl:element>
</xsl:template>
<xsl:template match="a-special-element">
<B:a-special-element xmlns:B="B">
<xsl:apply-templates match="children()"/>
</B:a-special-element>
</xsl:template>
</xsl:transform>
Run Code Online (Sandbox Code Playgroud)
我明白了
<foo xmlns="A" x="1">
<bar y="2">
<baz z="3"/>
</bar>
<B:a-special-element xmlns:B="B"/>
</foo>
Run Code Online (Sandbox Code Playgroud)
这就是你要找的东西吗?
| 归档时间: |
|
| 查看次数: |
25919 次 |
| 最近记录: |