【发布时间】:2015-04-04 18:15:09
【问题描述】:
我有一个 XML 数据结构,我正在使用 XSLT 将其转换为 HTML。我需要使用 XSLT 和输出将 XML 的 current_teaching 元素中的文本拆分为点(元素内容中的分号表示我希望在哪里进行拆分)。
到目前为止,这就是我所拥有的。
XML/XSLT 文件:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="StaffList.xslt"?>
<StaffList>
<StaffMember>
<title>Dr John Brown</title>
<titledesc>Senior Lecturer, ICU Security Research Institute</titledesc> <!-- example text -->
<telephone>(645) 2545 6988</telephone>
<mobile>04568 6665 666</mobile>
<facsimile>(61 8) 9999 9999</facsimile>
<email>dr.brown@brown.com</email>
<campus>Mountain Range</campus>
<room>18.13</room>
<description>John Brown is a awesome doctor.</description>
<current_teaching>Data Structures; Principles of Distributed Systems; Fundamentals of Software Engineering</current_teaching>
</StaffMember>
</StaffList>
XSLT:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
<link rel="stylesheet" type="text/css" href="StaffList.css"/>
</head>
<body>
<xsl:for-each select="StaffList/StaffMember">
<h2 id="title"><xsl:value-of select="title"/></h2>
<h3 id="titledesc"><xsl:value-of select="titledesc"/></h3>
<br></br>
<table>
<tr>
<td id="telephone_1">Telephone</td>
<td id="telephone_2"><xsl:value-of select="telephone"/></td>
</tr>
<tr>
<td id="mobile_1">Mobile</td>
<td id="mobile_2"><xsl:value-of select="mobile"/></td>
</tr>
<tr>
<td id="facsimile_1">Facsimile</td>
<td id="facsimile_2"><xsl:value-of select="facsimile"/></td>
</tr>
<tr>
<td id="email_1">Email</td>
<td id="email_2"><xsl:value-of select="email"/></td>
</tr>
<tr>
<td id="campus_1">Campus</td>
<td id="campus_2"><xsl:value-of select="campus"/></td>
</tr>
<tr>
<td id="room_1">Room</td>
<td id="room_2"><xsl:value-of select="room"/></td>
</tr>
</table>
<br></br>
<br></br>
<p><xsl:value-of select="description"/></p>
<br></br>
</xsl:for-each>
</body>
</html>
</xsl:template></xsl:stylesheet>
我进行了一些搜索,已经找到了一个可能的解决方案,但我无法让我的 XSLT 使用它。 这是我尝试过的:
<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>
这是在上述 XSLT 代码的最后一个 br /br 和 /xsl:for-each 之间添加的。
【问题讨论】:
-
您的样式表声明了 1.0 版。您正在尝试使用需要 XSLT 2.0 的
xsl:analyze-string。您实际使用的是哪种 XSLT 处理器? -
我现在用的是1.0,是不是只要把声明改成2.0那么简单?
-
不,您需要 XSLT 2.0 处理器才能使用 XSLT 2.0 功能。您使用的是哪个特定的 XSLT 1.0 处理器?如果您不确定,请在此处查看方法:stackoverflow.com/questions/25244370
-
从该线程中的代码输出是“Microsoft 1”