使用copy-of从XSLT输出添加额外的XML声明?

时间:2013-01-18 14:35:05

标签: xml xslt declaration

我有一块XSLT,它根据参数对父元素的所有子元素进行复制...

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <!-- Removes the XML tag from begginning of output -->
    <xsl:output omit-xml-declaration="yes" />
    <!-- Include external variables / data -->
    <xsl:namespace-alias stylesheet-prefix="testNS" result-prefix="testNS" />
    <xsl:template match="/">
        <xsl:copy-of select="/hostElement/*[position() > 1]" /> 
            <xsl:element name="anotherElement">
            <xsl:value-of select="count(//hostElement/childElement[position() > 1])"/>
        </xsl:element>
    </xsl:template>

运行后我得到以下输出......

<?xml version="1.0" encoding="UTF-8"?>
<hostElement xmlns=""><?xml version="1.0"?>
<childElement>...

它给出的输出似乎有一个额外的XML语句,它没有验证。命名空间也不存在......

有人可以试着帮助我吗?!

谢谢,

灰。

1 个答案:

答案 0 :(得分:0)

我正在使用一个名为Cast Iron的应用程序来进行这些转换。我现在已经找到了答案,Cast Iron默认添加这些,因为它无法在给定的输出中找到它们。只需添加<parentElement></parentElement>即可修复它,因为这正是它所期待的