我正在尝试从xml文件中的注释生成格式良好的html文档。目前我有一个xml文件,用于生成xml表的html列表。为了让我添加关于表的注释,我手动将注释添加到输出html文件中。
我想如果可能将html代码作为注释放在xml文件中,并让xslt使用注释来创建格式正确的文档。
以下是评论的xml文件的一部分。这里有html新行语法,我希望xslt读作html。我认为必须有一个更好的方法来使用原始xml来创建它,但是,我不希望在xml文件中读取注释,所以不要将它作为表条目。
<table name="ers_benchmark_defn" xmlns="">
<!-- This table contains mapping between hierarchy nodes and their respective benchmarks. The columns should be populated as follows:<br>
<ul>
<li>HIERARCHY_NODE<br>
This column contains the name of the hierarchy node in the ERS Risk Hierarchy.</ul>
<ul>
<li>BENCHMARK<br>
The column can be populated with either;<br>
a Calypso portfolio name,<br>
an ERS Risk Hierarchy name, or<br>
an ERS Risk Hierarchy node name.<br><br>
In the latter case, the column should be populated with the hierarchy node name and the hierarchy to which it belongs, separated by a percentage symbol, %.</ul>
<ul>
<li>BENCHMARK_TYPE<br>
If the value in the benchmark column is an ERS hierarchy or hierarchy node name, this column should be populated with the value HIERARCHY. Otherwise, when using a Calypso portfolio name, it should not be populated.</ul>
<ul>
<li>SCALING_FACTOR<br>
This column should be populated with the scaling factor by which the benchmark results should be multiplied. To use MTM scaling, leave this column unpopulated.</ul>
See the ERS 10.2 Release notes for further information.<br><br> -->
<column name="hierarchy_node" nullable="false" type="string" scale="255"/>
<column name="benchmark" nullable="false" type="string" scale="255"/>
<column name="benchmark_type" nullable="true" type="string" scale="32"/>
<column name="scaling_factor" nullable="true" type="float"/>
这是我使用评论的xsl文件的一部分,但它不解释html。
<tr class="info" width="100%">
<td colspan="4"><xsl:value-of select="comment()"/></td>
</tr>
手动格式化时,所需输出如下所示:
<p>
<table border="1" cellpadding="2" cellspacing="0">
<tr class="title">
<th colspan="4"><a name="ers_benchmark_defn"></a>ers_benchmark_defn
</th>
</tr>
<tr class="info" width=100%>
<th colspan=4 align=left>This table contains mapping between hierarchy nodes and their respective benchmarks. The columns should be populated as follows:<br>
<ul>
<li>HIERARCHY_NODE<br>
This column contains the name of the hierarchy node in the ERS Risk Hierarchy.</ul>
<ul>
<li>BENCHMARK<br>
The column can be populated with either;<br>
a Calypso portfolio name,<br>
an ERS Risk Hierarchy name, or<br>
an ERS Risk Hierarchy node name.<br><br>
In the latter case, the column should be populated with the hierarchy node name and the hierarchy to which it belongs, separated by a percentage symbol, %.</ul>
<ul>
<li>BENCHMARK_TYPE<br>
If the value in the benchmark column is an ERS hierarchy or hierarchy node name, this column should be populated with the value HIERARCHY. Otherwise, when using a Calypso portfolio name, it should not be populated.</ul>
<ul>
<li>SCALING_FACTOR<br>
This column should be populated with the scaling factor by which the benchmark results should be multiplied. To use MTM scaling, leave this column unpopulated.</ul>
See the ERS 10.2 Release notes for further information.<br><br></th>
</tr>
<tr class="header">
<th>column name</th>
<th>nullable</th>
<th>type</th>
这些是完整代码的摘录,但我认为这应该足以帮助我。
谢谢!
答案 0 :(得分:1)
哦,我猜你在谈论XML文件中的 <!CDATA[...]]>
,请查看w3schools页面。
在您的示例中,我创建了一个comments
元素(使用您最喜欢的名称),并引入disable-output-escaping
属性,以避免HTML scaping。
会是这样的:
<table name="ers_benchmark_defn" xmlns="">
<comments>
<![CDATA[This table contains mapping between hierarchy nodes and their respective benchmarks. The columns should be populated as follows:<br>
<ul>
<li>HIERARCHY_NODE<br>
This column contains the name of the hierarchy node in the ERS Risk Hierarchy.</ul>
<ul>
<li>BENCHMARK<br>
The column can be populated with either;<br>
a Calypso portfolio name,<br>
an ERS Risk Hierarchy name, or<br>
an ERS Risk Hierarchy node name.<br><br>
In the latter case, the column should be populated with the hierarchy node name and the hierarchy to which it belongs, separated by a percentage symbol, %.</ul>
<ul>
<li>BENCHMARK_TYPE<br>
If the value in the benchmark column is an ERS hierarchy or hierarchy node name, this column should be populated with the value HIERARCHY. Otherwise, when using a Calypso portfolio name, it should not be populated.</ul>
<ul>
<li>SCALING_FACTOR<br>
This column should be populated with the scaling factor by which the benchmark results should be multiplied. To use MTM scaling, leave this column unpopulated.</ul>
See the ERS 10.2 Release notes for further information.<br><br>]]>
</comments>
<column name="hierarchy_node" nullable="false" type="string" scale="255"/>
<column name="benchmark" nullable="false" type="string" scale="255"/>
<column name="benchmark_type" nullable="true" type="string" scale="32"/>
<column name="scaling_factor" nullable="true" type="float"/>
在您的XSL文件中:
<tr class="info" width="100%">
<td colspan="4"><xsl:value-of select="comments" disable-output-escaping="yes" /></td>
</tr>
Ps:如果您仍然遇到输出问题,请尝试在XML版本声明后插入此xsl:output
行XSL(更多信息here):
<xsl:output method="html" omit-xml-declaration="no" indent="yes" />