coldfusion xmltransform显示为一个大块

coldfusion xmltransform显示为一个大块,xml,xslt,coldfusion,coldfusion-9,Xml,Xslt,Coldfusion,Coldfusion 9,我正在玩弄XML和XSL。我有一个XML文件,看起来有点像这样: <?xml version="1.0" encoding="utf-8"?> <?xml-stylesheet href="/_xslt/xslt_terms.xsl" type="text/xsl" ?> <terms> <term><p>Use of Website</p> <term>

我正在玩弄XML和XSL。我有一个XML文件,看起来有点像这样:

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet href="/_xslt/xslt_terms.xsl" type="text/xsl" ?>
    <terms>
       <term><p>Use of Website</p>
           <term>
                <term><p>wording here</p></term>
                <term><p>more words!</p></term>
           </term>
        <term><p>serious words</p></term>
    </terms>
但是当我跑的时候

<cfoutput>
     <cffile action="read" 
             file="#application.sPath#_xslt/xslt_terms.xsl" 
             variable="variables.xmltrans">
     <cfset variables.xmldoc = XmlParse("#application.sPath#_templates/_ajax/_terms/xml_terms.xml")>
     #XMLTransform(variables.xmldoc, variables.xmltrans)#
</cfoutput>
正如我所说的,这是自..以来我第一次使用XML和XSL。。很长时间了,所以我可能错过了什么

编辑

我找到了一些代码来帮助完成这项工作。我已将xml更改为删除所有
标记,并将xsl文件更改为:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output indent="yes"/>

    <xsl:template match="@*|node()">
            <xsl:copy>
                <xsl:apply-templates select="@*|node()"/>
            </xsl:copy>
    </xsl:template>

<xsl:template match="term">
    <p>
        <xsl:number format="1." level="multiple"/>
        <xsl:apply-templates select="@*|node()"/>
    </p>
</xsl:template>



这几乎可以做到,但我正在失去缩进,我能做些什么使它像上面那样缩进吗?

如果您能确保插入XSLT输出的完整HTML文档可以包含一些CSS,那么我建议创建一个HTML有序嵌套列表,其中的数字是用CSS完成的:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">

    <xsl:strip-space elements="*"/>
    <xsl:output method="html" indent="yes" version="5.0"/>

    <xsl:template match="/">
        <html>
            <head>
                <title>list test</title>
                <style>
                    ol.nested  { counter-reset: section; list-style-type: none; }
                    ol.nested li { counter-increment: section; }
                    ol.nested li:before { content: counters(section, ".") ". "; }
                </style>
            </head>
            <body>
                <xsl:apply-templates/>
            </body>
        </html>
    </xsl:template>

    <xsl:template match="terms[term]">
        <ol class="nested">
            <xsl:apply-templates/>
        </ol>
    </xsl:template>

    <xsl:template match="term">
        <li>
            <xsl:apply-templates select="node()[not(self::term)]"/>
            <xsl:if test="term">
                <ol class="nested">
                    <xsl:apply-templates select="term"/>
                </ol>
            </xsl:if>
        </li>
    </xsl:template>
</xsl:stylesheet>

列表测试
ol.nested{计数器重置:节;列表样式类型:无;}
ol.L{计数器增量:节;}
ol.li:在{content:counters(第节“.”之前;}
  • 输入XML为

    <?xml-stylesheet type="text/xsl" href="sheet.xsl"?>
    <terms>
        <term><p>Use of Website</p>
            <term>
                <term><p>wording here</p></term>
                <term><p>more words!</p></term>
            </term>
            <term><p>serious words</p></term>
        </term>
    </terms>
    
    
    网站的使用

    这里的措辞

    更多的话

    严肃的话

    现代浏览器会将其呈现为一个嵌套列表,其中包含您想要的计数

    如果您想使用XSLT创建数字,那么我仍然会创建一个HTML列表,因为HTML需要结构化:

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        version="1.0">
    
        <xsl:strip-space elements="*"/>
        <xsl:output method="html" indent="yes" version="5.0"/>
    
        <xsl:template match="terms[term]">
            <ol style="list-style-type: none;">
                <xsl:apply-templates/>
            </ol>
        </xsl:template>
    
        <xsl:template match="term">
            <li><xsl:number level="multiple" format="1. "/>
                <xsl:apply-templates select="node()[not(self::term)]"/>
                <xsl:if test="term">
                    <ol style="list-style-type: none;">
                        <xsl:apply-templates select="term"/>
                    </ol>
                </xsl:if>
            </li>
        </xsl:template>
    </xsl:stylesheet>
    
    
    
  • 现在,当应用于输入时

    <?xml-stylesheet type="text/xsl" href="sheet.xsl"?>
    <terms>
        <term><p>Use of Website</p>
            <term>
                <term><p>wording here</p></term>
                <term><p>more words!</p></term>
            </term>
            <term><p>serious words</p></term>
        </term>
    </terms>
    
    
    网站的使用

    这里的措辞

    更多的话

    严肃的话


    您可以获得所需的编号。

    如果您可以确保插入XSLT输出的完整HTML文档可以包含一些CSS,那么我建议创建一个HTML有序嵌套列表,其中的编号是通过CSS完成的:

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        version="1.0">
    
        <xsl:strip-space elements="*"/>
        <xsl:output method="html" indent="yes" version="5.0"/>
    
        <xsl:template match="/">
            <html>
                <head>
                    <title>list test</title>
                    <style>
                        ol.nested  { counter-reset: section; list-style-type: none; }
                        ol.nested li { counter-increment: section; }
                        ol.nested li:before { content: counters(section, ".") ". "; }
                    </style>
                </head>
                <body>
                    <xsl:apply-templates/>
                </body>
            </html>
        </xsl:template>
    
        <xsl:template match="terms[term]">
            <ol class="nested">
                <xsl:apply-templates/>
            </ol>
        </xsl:template>
    
        <xsl:template match="term">
            <li>
                <xsl:apply-templates select="node()[not(self::term)]"/>
                <xsl:if test="term">
                    <ol class="nested">
                        <xsl:apply-templates select="term"/>
                    </ol>
                </xsl:if>
            </li>
        </xsl:template>
    </xsl:stylesheet>
    
    
    列表测试
    ol.nested{计数器重置:节;列表样式类型:无;}
    ol.L{计数器增量:节;}
    ol.li:在{content:counters(第节“.”之前;}
    
  • 输入XML为

    <?xml-stylesheet type="text/xsl" href="sheet.xsl"?>
    <terms>
        <term><p>Use of Website</p>
            <term>
                <term><p>wording here</p></term>
                <term><p>more words!</p></term>
            </term>
            <term><p>serious words</p></term>
        </term>
    </terms>
    
    
    网站的使用

    这里的措辞

    更多的话

    严肃的话

    现代浏览器会将其呈现为一个嵌套列表,其中包含您想要的计数

    如果您想使用XSLT创建数字,那么我仍然会创建一个HTML列表,因为HTML需要结构化:

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        version="1.0">
    
        <xsl:strip-space elements="*"/>
        <xsl:output method="html" indent="yes" version="5.0"/>
    
        <xsl:template match="terms[term]">
            <ol style="list-style-type: none;">
                <xsl:apply-templates/>
            </ol>
        </xsl:template>
    
        <xsl:template match="term">
            <li><xsl:number level="multiple" format="1. "/>
                <xsl:apply-templates select="node()[not(self::term)]"/>
                <xsl:if test="term">
                    <ol style="list-style-type: none;">
                        <xsl:apply-templates select="term"/>
                    </ol>
                </xsl:if>
            </li>
        </xsl:template>
    </xsl:stylesheet>
    
    
    
  • 现在,当应用于输入时

    <?xml-stylesheet type="text/xsl" href="sheet.xsl"?>
    <terms>
        <term><p>Use of Website</p>
            <term>
                <term><p>wording here</p></term>
                <term><p>more words!</p></term>
            </term>
            <term><p>serious words</p></term>
        </term>
    </terms>
    
    
    网站的使用

    这里的措辞

    更多的话

    严肃的话


    您可以获得所需的编号。

    请显示XSLT的更多详细信息,特别是
    xsl:output方法
    。另外,请告诉我们随服务器端代码一起发送的HTTP
    内容类型
    头。您发送的是
    text/plain
    还是
    text/html
    ?啊,XSL的代码就是整个代码。。。所以我显然错过了一些东西。现在我来看看
    xsl:output
    <代码>内容类型为:
    text/html;charset=UTF-8
    如果内容类型是text/html,那么您需要确保XSLT创建html而不是像当前那样创建纯文本,否则浏览器会将您的文本行呈现为html,并使用html将空白折叠为空白,这样您只需获得一行文本。因此,请将内容类型更改为text/plain或确保XSLT创建构成输出的HTML元素。我无法将整个页面作为text/plain输出,因为它嵌入在HTML页面中。。所以我应该在xsl中使用
    。。。尽管这样做仍然会留下一大块文本。@MartinHonnen查看我的新代码。差不多了。请显示XSLT的更多详细信息,特别是
    xsl:output方法
    。另外,请告诉我们随服务器端代码一起发送的HTTP
    内容类型
    头。您发送的是
    text/plain
    还是
    text/html
    ?啊,XSL的代码就是整个代码。。。所以我显然错过了一些东西。现在我来看看
    xsl:output
    <代码>内容类型为:
    text/html;charset=UTF-8
    如果内容类型是text/html,那么您需要确保XSLT创建html而不是像当前那样创建纯文本,否则浏览器会将您的文本行呈现为html,并使用html将空白折叠为空白,这样您只需获得一行文本。因此,请将内容类型更改为text/plain或确保XSLT创建构成输出的HTML元素。我无法将整个页面作为text/plain输出,因为它嵌入在HTML页面中。。所以我应该在xsl中使用
    。。。虽然那样做很有趣