我在玩 XML 和 XSL。我有一个看起来像这样的 XMLfile:
<?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>
和一个看起来像的 XSL 文件
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml" >
<xsl:template match="term">
<xsl:number level="multiple" format="1. "/>
<xsl:apply-templates/>
</xsl:template>
</xsl:stylesheet>
输出应显示为
1. Use of Website
1.1.
1.1.1. wording here
1.1.2. more words
1.2. serious words
但是当我跑步时
<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>
我得到一大块没有换行符的文本。所以它看起来像:
1. Use of Website 1.1. 1.1.1. wording here 1.1.2. more words 1.2. serious words
正如我所说,这是我第一次使用 XML 和 XSL,因为......很长一段时间,所以我很可能错过了一些东西
编辑
我找到了一些代码来帮助几乎完成这项工作。我已更改我的 xml 以删除所有<p>
标签,并且我已将我的 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>
这几乎可以做到,但我失去了缩进,我能做些什么让它像上面那样缩进吗?