1

我有一个 XML 文档,一个标签的描述很长,所以我想用几个要点格式化它

例如,

<description>This course is an introduction to the information technologies required for secure, practical information systems for electronic commerce.
Topics will be chosen from areas such as document representation (XML, DTDs, XML Schema, XSLT, CSS), security (encryption, public key, symmetric key, 
PKI, authentication); kinds of attack and vulnerabilities, electronic trading (spontaneous, deliberative, auctions), electronic document management 
(metadata, search, digital libraries, management and processing), recent developments and maturation of the area, 
such as web application frameworks, web services, the semantic web , mobile commerce</description>

我希望这是一些类似的东西

  • 本课程介绍安全、实用的电子商务信息系统所需的信息技术。
  • 主题将从文档表示
    (XML、DTD、XML Schema、XSLT、CSS)、安全性(加密、公钥、对称密钥、PKI、身份验证)等领域中选择;各种攻击和
    漏洞、电子交易(自发、慎重、
    拍卖),
  • 电子文档管理(元数据、搜索、数字图书馆、管理和处理)、该领域的最新发展和成熟,例如网络应用程序框架、网络服务、语义网络、移动商务

为此,我相信我应该更改我的 XSL 文件中的某些内容,即

<xsl:template match="/">
    <html>
    <head>
        <title> Course Catalogue </title>
    </head>
    <body bgcolor="#FF9999">
        <xsl:for-each select="xsi:catalogue/xsi:course">
            <br />
            <xsl:apply-templates select="xsi:title" />
            <br />
            <xsl:apply-templates select="xsi:year" />
            <br />
            <xsl:apply-templates select="xsi:science" />
            <br />
            <xsl:apply-templates select="xsi:area" />
            <br />
            <xsl:apply-templates select="xsi:subject" />
            <br />
            <xsl:apply-templates select="xsi:unit" />
            <br />
            <xsl:apply-templates select="xsi:description" />
            <br />
            <xsl:apply-templates select="xsi:outcomes" />
            <br />
            <xsl:apply-templates select="xsi:incompatibility" />
        </xsl:for-each>
    </body>
    </html>
</xsl:template>

对于 xsi:description,

<!-- The template for course description --> 
<xsl:template match="xsi:description">
    <div style="font-family:times;font-size:16">
        <span style="color:#000"> 
            Course Description: 
        </span> 
        <xsl:value-of select="." />
    </div>
</xsl:template>

我应该如何包括要点?谢谢!

4

1 回答 1

1

您将不得不决定分隔符以将您的描述拆分为项目符号。这是一个使用句点和分号作为分隔符的示例:

模板:

<xsl:template match="xsi:description">
    <div style="font-family:times;font-size:16">
        <span style="color:#000">Course Description:</span> 
        <ul>
            <xsl:analyze-string select="string()" regex=".*?[\.;]" flags="sm">
                <xsl:matching-substring>
                    <li><xsl:value-of select="."/></li>
                </xsl:matching-substring>
                <xsl:non-matching-substring>
                    <li><xsl:value-of select="."/></li>
                </xsl:non-matching-substring>
            </xsl:analyze-string>
        </ul>            
    </div>
</xsl:template>

输出:

<div style="font-family:times;font-size:16">
    <span style="color:#000">Course Description:</span>
    <ul>
        <li>This course is an introduction to the information technologies required for secure, practical information systems for electronic commerce.</li>
        <li>Topics will be chosen from areas such as document representation (XML, DTDs, XML Schema, XSLT, CSS), security (encryption, public key, symmetric key, PKI, authentication);</li>
        <li> kinds of attack and vulnerabilities, electronic trading (spontaneous, deliberative, auctions), electronic document management (metadata, search, digital libraries, management and processing), recent developments and maturation of the area, such as web application frameworks, web services, the semantic web , mobile commerce</li>
    </ul>
</div>

.*?[\.;]如果您想使用不同的规则来分解段落,您可以将正则表达式值更改为其他值。

于 2012-09-20T16:45:59.120 回答