使用 xsl 创建段落
嘿,我想知道是否有人对如何从 XML 文件中获取换行符并使用 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 文档保留段落结构。
谢谢, 乙
Hey, I was wandering if anyone had any suggestions on how to take new-lines from an XML file and convert them to paragraphs with an XSL transform.
Here is a what the XML structure looks like:
<?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>
And here is a copy of the XSL sheet I'm using for the transform.
<?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>
Again, my question pertains to what commands to use to preserve the paragraph structure using the existing XSL document.
Thanks,
E
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
发布评论
评论(2)
我的奇迹2024-11-05 04:30:52
查看 FXSL 1.2,http://sourceforge.net/projects/fxsl/。我无法回答这个项目的质量和实用性,但至少它包含很多东西和一些你可能需要的东西。
否则,攻击将是选择正文的文本节点,并使用 substring-before 和 substring-after 函数递归创建新的文本节点,并用“p”节点包围每个新文本节点。递归位可能是棘手的部分,但上面提到的代码中有很多示例。
~没有更多了~
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
此转换:
应用于提供的 XML 文档时:
产生所需的正确结果:
说明:身份规则 + 一个递归命名模板,用于将每个由 NL 字符包围的文本子字符串包装到
p
中。This transformation:
when applied on the provided XML document:
produces the wanted, correct result:
Explanation: The identity rule + a recursive named template for wrapping into a
p
each text substring surrounded by NL characters.