使用 xml 注释生成格式化的 html 输出

发布于 2024-11-07 16:52:36 字数 4450 浏览 3 评论 0原文

我正在尝试根据 xml 文件中的注释生成格式良好的 html 文档。目前我有一个 xml 文件,用于生成 xml 表的 html 列表。为了添加有关表格的注释,我手动将注释添加到输出 html 文件中。

我想如果可能的话将 html 代码作为注释放在 xml 文件中,并让 xslt 使用注释来创建格式正确的文档。

这是 xml 文件中被注释的部分。这里有 html new line 语法,我希望 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>

这些是完整代码的摘录,但我认为这应该足以让有人帮助我。

谢谢你!

I'm trying to generate a nicely formatted html document from the comments that I have in an xml file. At present I have an xml file that is used to generate an html list of the xml tables. In order for me to add comments about the tables I am manually adding the comments into the output html file.

I would like If possible to put the html code in the xml file as a comment and have xslt use the comment to create the correctly formatted document.

Here is the part of the xml file that is commented. Here there is html new line syntax that I would like xslt to read as html. I'm thinking there must be a better way to use raw xml to create this but, I don't want the comments to be read in the xml file so don't want it as a table entry.

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

This is the part of the xsl file that I have made to use the comment, however it does not interpret the html.

<tr class="info" width="100%">
        <td colspan="4"><xsl:value-of select="comment()"/></td>
    </tr>

The required output looks like this when manually formatted:

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

These are extracts of the full code but I think this should be enough for someone to help me.

Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

满天都是小星星 2024-11-14 16:52:36

哦,我猜你正在谈论 XML 文件中的 ,请检查 w3schools 页面有关它。

在您的示例中,我创建了一个 comments 元素(使用您最喜欢的名称),并引入 disable-output-escaping 属性,以避免 HTML 缩放。

它会像这样:

<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 的 xsl:output 行(更多信息 此处):

<xsl:output method="html" omit-xml-declaration="no" indent="yes" />

Oh, I guess you are talking about <!CDATA[...]]> in XML files, check w3schools page about it.

In your example, I create a comments element (use the name you best like), and introduce disable-output-escaping attribute, to avoid HTML scaping.

It would go like this:

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

In your XSL file:

<tr class="info" width="100%">
    <td colspan="4"><xsl:value-of select="comments" disable-output-escaping="yes" /></td>
</tr>

Ps: If you're still having problems with the output, try inserting this xsl:outputline of XSL after your XML version declaration (more info here):

<xsl:output method="html" omit-xml-declaration="no" indent="yes" />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文