嘿,如果有人對如何從XML文件中取出換行符並將它們轉換爲帶有XSL轉換的段落有任何建議,我都會徘徊。使用xsl創建段落
這裏是一個XML結構的樣子:
<?xml version="1.0" encoding="ISO-8859-1"?>
<document>
<book>
<issue>1</issue>
<body>
「Dude, I can't believe you fed it to your cat. That's crazy!」
「Yeah, dude, he just cuddled up next to me and started purring.」
「Then what did he do?」
「He just kept purring, man. He's been purring non-stop for like two weeks now. I can't even sleep.」
</body>
</book>
</document>
這裏是我使用的變換XSL表的副本。
<?xml version="1.0" encoding="ISO-8859-1"?>
<html xsl:version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml">
<body style="font-family:Arial;font-size:12pt;">
<xsl:for-each select="document/book">
<div style="color:red; padding:4px;">
<span style="font-weight:bold">
</span> Chapter
<xsl:value-of select="info/issue"/>
</div>
<div style="margin-left:10px; margin-bottom:1em; margin-right:25px; font-size:10pt;">
<span>
<xsl:value-of select="body"/>
</span>
</div>
</xsl:for-each>
</body>
</html>
同樣,我的問題涉及使用現有的XSL文檔保留段落結構的命令。
感謝, ē
@ user633264:最簡單的方法是使用'xsl:appy-templates select =「body」'而不是'xsl:value-of',然後用新的行字符標記文本節點(記住這是標準化爲' #xA;')添加'br'元素或包裝到'p'元素中。這裏有很多例子。 – 2011-03-31 16:04:26
好問題,+1。查看我的答案,獲得完整,簡短和簡單的解決方案。 – 2011-04-01 13:40:52