【发布时间】:2016-11-14 15:50:46
【问题描述】:
我正在使用 XLST 1.0 并想Transform XML to add 'nil' attributes to empty elements。我发现命名空间被添加到每个匹配的元素中,例如我的输出看起来像:
<age xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true" />
我知道这是有效的,但我宁愿将它添加到我的顶级节点。我遇到了这个答案:How can I add namespaces to the root element of my XML using XSLT?
但是我有多个可能的根节点,所以我想我可以这样做:
<xsl:template match="animals | people | things">
<xsl:element name="{name()}">
<xsl:attribute name="xmlns:xsi">http://www.w3.org/2001/XMLSchema-instance</xsl:attribute>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
但是我从 Visual Studio 中得到一个错误“prexix xmlns not defined”,我不知道该怎么做。
Here is my total XLST file(由于某种原因它不会粘贴到 SO)它试图做一些事情:
- 将不同类型的动物转化为单一类型
- 将命名空间添加到根节点
- 将
xsi:nil = true添加到空元素(注意它们必须没有子元素,而不仅仅是没有文本,否则我的顶级节点会被转换)
【问题讨论】: