2012-03-25 59 views
0

任何人都可以帮助我理解为什么这段代码会抛出xml提前结束的文件错误?coldfusion xml xslt文件错误提前结束

<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

+0

这很容易调试。从“”的内容中删除行,并查看它停止工作的位置。 XSLT本身看起来很好。 – Tomalak 2012-03-25 21:27:47

+0

在我的回复中取得了一个高峰,我尝试删除所有内容,仍然没有去 – 2012-03-25 21:29:53

+0

您的CF页面中有一个空的'',这会产生错误?难以置信。 – Tomalak 2012-03-25 21:31:18

回答

0

我最终改变我的解决方案完全与我在这里发布的内容滚动:coldfusion xml menu感谢您的帮助@Tomalak。

1

课外阅读各种意见后运行它,我不得不实施本的解决方案如下。不知道这是冷藏箱还是别的什么,但是这里就是了。

先到这里是模型法:

<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> 

,我不得不删除所有的评论太

+0

评论是完全有效的ColdFusion评论。他们不会破坏任何东西。 – Tomalak 2012-03-25 21:30:14

+0

我想了很多,只是想我会尝试,但没有骰子 – 2012-03-25 21:32:29