coldfusion xml xslt过早结束文件错误

时间:2012-03-25 21:18:03

标签: xml coldfusion menu

任何人都可以帮助我理解为什么这个代码块会引发文件错误的xml过早结束吗?

    <cfxml variable="xslt">
        <xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
            <!--- Start by matching the root node. --->
            <xsl:template match="/nodes">
                <nodes>
                    <!---
                        Inside our new root node, output all the top-
                        level NODE elements (ie. those with a parentID
                        value of zero).
                    --->
                    <xsl:call-template name="getChildNodes" />
                </nodes>
            </xsl:template>
            <!--- This function outputs all child node elemenst of the node with the given ID. --->
            <xsl:template name="getChildNodes">
                <!--- Param our parent ID. --->
                <xsl:param name="parentID" select="0" />
                <!--- Select all the child node elements that have the given parentID. --->
                <xsl:for-each select="//node[@parent-id=$parentID]">
                    <!--- Sort this node list on ID. --->
                    <xsl:sort select="@id" />
                    <!--- Output the new node. --->
                    <node id="{@id}" parent-id="{@parent-id}" name="{@name}">
                        <!---
                            Now that are outputting a given node, let's
                            output all the child nodes that might be a
                            descendant of it.

                            NOTE: This is the recursive aspect of this
                            XSTL approach.
                        --->
                        <xsl:call-template name="getChildNodes">
                            <xsl:with-param name="parentID" select="@id"/>
                        </xsl:call-template>
                    </node>
                </xsl:for-each>
            </xsl:template>
        </xsl:transform>
    </cfxml>

上述部分是此完整功能的一部分:

<cffunction name="xmlNav" access="private" returntype="struct" output="false">
    <cfargument name="qGetNav" type="query" required="true">
    <cfset var qNav = arguments.qGetNav>
    <cfset var rawNodeTree="">
    <cfset var xslt="">
    <cfxml variable="rawNodeTree">
        <cfoutput>
        <nodes>
            <cfloop query="qNav">
                <node id="#qNav.navid#" parent-id="#qNav.navparentID#" name="#qNav.TextDesc#"/>
            </cfloop>
        </nodes>
        </cfoutput>
    </cfxml>
    <cfxml variable="xslt">
        <xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
            <!--- Start by matching the root node. --->
            <xsl:template match="/nodes">
                <nodes>
                    <!---
                        Inside our new root node, output all the top-
                        level NODE elements (ie. those with a parentID
                        value of zero).
                    --->
                    <xsl:call-template name="getChildNodes" />
                </nodes>
            </xsl:template>
            <!--- This function outputs all child node elemenst of the node with the given ID. --->
            <xsl:template name="getChildNodes">
                <!--- Param our parent ID. --->
                <xsl:param name="parentID" select="0" />
                <!--- Select all the child node elements that have the given parentID. --->
                <xsl:for-each select="//node[@parent-id=$parentID]">
                    <!--- Sort this node list on ID. --->
                    <xsl:sort select="@id" />
                    <!--- Output the new node. --->
                    <node id="{@id}" parent-id="{@parent-id}" name="{@name}">
                        <!---
                            Now that are outputting a given node, let's
                            output all the child nodes that might be a
                            descendant of it.

                            NOTE: This is the recursive aspect of this
                            XSTL approach.
                        --->
                        <xsl:call-template name="getChildNodes">
                            <xsl:with-param name="parentID" select="@id"/>
                        </xsl:call-template>
                    </node>
                </xsl:for-each>
            </xsl:template>
        </xsl:transform>
    </cfxml>

    <cfset myXmlNav.xmlNav=rawNodeTree>
    <cfset myXmlNav.IsXml=IsXML(myXmlNav.xmlNav)>
    <cfreturn myXmlNav>
</cffunction>

我已经确认我可以在cfc

之外自己运行它

2 个答案:

答案 0 :(得分:1)

阅读各种评论后,我必须按照以下方式实施ben的解决方案。不确定它是冷箱还是别的什么,但是现在就去了。

首先是模型方法:

<cffunction name="xmlNav" access="private" returntype="struct" output="false">
    <cfargument name="qGetNav" type="query" required="true">
    <cfset var qNav = arguments.qGetNav>
    <cfset var rawNodeTree="">
    <cfset var xslt="">
    <cfset var xsltfile="#Instance.AppShared.AppServerInfo.ApplicationPath#\model\layout\MenuXsl">
    <!--- Reference: http://www.bennadel.com/blog/2045-Ask-Ben-Converting-A-Parent-Child-Data-Table-Into-A-Nested-XML-Document.htm --->
    <cfxml variable="rawNodeTree">
        <cfoutput>
        <nodes>
            <cfloop query="qNav">
                <node id="#qNav.navid#" parent-id="#qNav.navparentID#" name="#qNav.TextDesc#"/>
            </cfloop>
        </nodes>
        </cfoutput>
    </cfxml>
    <cffile action="Read" file="#xsltfile#" variable="xslt"> 
    <cfset xslt=XmlParse(xslt)>

    <cfset myXmlNav.xslt=xslt>
    <cfset myXmlNav.xmlNav=rawNodeTree>
    <cfset myXmlNav.xmlNav=XmlParse(xmlTransform(myXmlNav.xmlNav,myXmlNav.xslt))>
    <cfreturn myXmlNav>
</cffunction>

,第二个是xslt文件:

<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/nodes">
        <nodes>
            <xsl:call-template name="getChildNodes" />
        </nodes>
    </xsl:template>
    <xsl:template name="getChildNodes">
        <xsl:param name="parentID" select="0" />
        <xsl:for-each select="//node[@parent-id=$parentID]">
            <xsl:sort select="@id" />
            <node id="{@id}" parent-id="{@parent-id}" name="{@name}">
                <xsl:call-template name="getChildNodes">
                    <xsl:with-param name="parentID" select="@id"/>
                </xsl:call-template>
            </node>
        </xsl:for-each>
    </xsl:template>
</xsl:transform>

我不得不删除所有评论

答案 1 :(得分:0)

我最终完全改变了我的解决方案并按照我在此处发布的内容滚动:coldfusion xml menu感谢您的帮助@Tomalak。