【发布时间】:2018-03-28 09:14:48
【问题描述】:
我一直坚持使用 XSLT 将 XML 转换为 HTML,其中 XML 中的记录包含多个具有相同名称但标签、标签和内容不同的嵌套元素。
我的 XML 包含如下记录:
<catalog>
<catalogKey>77971</catalogKey>
<yearOfPublication>1999</yearOfPublication>
<marc>
<marcEntry tag="035" label="Local system #" ind=" ">77971</marcEntry>
<marcEntry tag="035" label="Local system #" ind=" ">DIT87496</marcEntry>
<marcEntry tag="245" label="Title" ind=" 0">3D Studio MAX 3 fundamentals [electronic resource].</marcEntry>
<marcEntry tag="260" label="Publication info" ind=" ">Indianapolis, Ind. : New Riders, 1999.</marcEntry>
<marcEntry tag="300" label="Physical descript" ind=" ">1 computer laser optical disk</marcEntry>
<marcEntry tag="500" label="General Note" ind=" ">Use with book: 3D Studio MAX 3 fundamentals / Michael Todd Peterson</marcEntry>
<marcEntry tag="520" label="Abstract/summary" ind=" ">"The CD-ROM is loaded with .MAX and .AVI files to follow along with the tutorials, including plug-ins, images, sample animations, models, and textures. Bonus Lotus ScreenCam movies are included to enhance the learning process by providing a visual reference for each tutorial."</marcEntry>
<marcEntry tag="538" label="Technical details" ind=" ">CD-ROM disk</marcEntry>
<marcEntry tag="650" label="Subject term" ind=" 0">Computer graphics--Computer programs.</marcEntry>
<marcEntry tag="650" label="Subject term" ind=" 0">3d studio (Computer program)</marcEntry>
</marc>
<call>
<item>
<copyNumber>1</copyNumber>
<itemID>DUT2000-2102</itemID>
<library>STEVEBIKO</library>
<libraryDescription>Alan Pittendrigh Library (Steve Biko Campus)</libraryDescription>
<location>DISCARD</location>
<homeLocation>DISCARD13</homeLocation>
<price currency="R" >80.25</price>
<category1>CDROMS</category1>
<type>MMSTLN</type>
<numberOfPieces>1</numberOfPieces>
<dateCreated>2005-11-11</dateCreated>
<isPermanent>true</isPermanent>
</item>
</call>
</catalog>
我需要这个以 HTML 格式显示:
77971 1999 035 77971
035 DIT87496
245 3D Studio MAX 3 fundamentals
...
1 DUT2000-2102 STEVEBIKO DISCARD DISCARD13 80.25 CDROMS MMSTLN 1 2005-11-11
但我能做到的最好的是:
77971 1999 77971
1 DUT2000-2102 STEVEBIKO DISCARD DISCARD13 80.25 CDROMS MMSTLN 1 2005-11-11
与:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<xsl:for-each select="report/catalog">
<tr>
<td><xsl:value-of select="catalogKey"/></td>
<td><xsl:value-of select="yearOfPublication"/></td>
<xsl:for-each select="marc">
<td>
<xsl:value-of select="marcEntry"/>
</td>
</xsl:for-each>
</tr>
<xsl:for-each select="call">
<xsl:for-each select="item">
<tr>
<td></td>
<td></td>
<td></td>
<td><xsl:value-of select="copyNumber"/></td>
<td><xsl:value-of select="itemID"/></td>
<td><xsl:value-of select="library"/></td>
<td><xsl:value-of select="location"/></td>
<td><xsl:value-of select="homeLocation"/></td>
<td><xsl:value-of select="price"/></td>
<td><xsl:value-of select="category1"/></td>
<td><xsl:value-of select="type"/></td>
<td><xsl:value-of select="numberOfPieces"/></td>
<td><xsl:value-of select="dateCreated"/></td>
</tr>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
我需要帮助的是将多个具有相同名称但标签和内容不同的嵌套元素转换为 HTML。 marcEntry 标签会因记录而异。
【问题讨论】: