xml - 删除单个节点上的缩进
问题描述
我希望在不添加缩进 =“否”的情况下调整单个节点。
<xsl:output method="html" indent="no" html-version="5"/>
在测试“normalize-space”和“translate”时,它们工作正常,假设 indent 设置为 no,但该设置会影响整个文档。
问题: 如何删除单行的缩进?
您可以在此处找到代码示例: https ://xsltfiddle.liberty-development.net/6qaHaQL/1
下面是相同的代码:
XML:
<?xml version="1.0" encoding="utf-8" ?>
<data
xmlns:base="http://www.example.org/1"
>
<base:Content book="Alice">
<chapterOne>
Alice was beginning to get very tired of sitting by her sister on the bank, and of having nothing to do: once or twice she had peeped into the book her sister was reading.
</chapterOne>
</base:Content>
<base:Content book="Alice">
<chapterTwo>
There seemed to be no use in waiting by the little door, so she went back to the table, half hoping she might find another key on it, or at any rate a book of rules for shutting people up like telescopes
</chapterTwo>
</base:Content>
</data>
XSL:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
xmlns:base="http://www.example.org/1"
>
<!--xsl:output method="html" indent="no" html-version="5"/>-->
<xsl:output method="html" html-version="5"/>
<xsl:template match="/data">
<html>
<body>
Chapter one:
<xsl:value-of select="normalize-space(base:Content/chapterOne)"/>
<!-- Test [1] Use [normalize-space]. Works if adding [indent="no"] -->
<!--xsl:value-of select="normalize-space(base:Content/chapterOne)"/>-->
<!-- Test [2] Use [translate]. Works if adding [indent="no"] -->
<!--xsl:value-of select="translate(base:Content/chapterOne, '
', '')"/>-->
Chapter two:
<xsl:value-of select="base:Content/chapterTwo"/>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
当前结果:
<!DOCTYPE HTML>
<html xmlns:base="http://www.example.org/1">
<body>
Chapter one:
Alice was beginning to get very tired of sitting by her sister on the bank, and of
having nothing to do: once or twice she had peeped into the book her sister was reading.
Chapter two:
There seemed to be no use in waiting by the little door, so she went back to the table,
half hoping she might find another key on it, or at any rate a book of rules for shutting
people up like telescopes
</body>
</html>
想要的结果
<!DOCTYPE HTML>
<html xmlns:base="http://www.example.org/1"><body>
Chapter one:
Alice was beginning to get very tired of sitting by her sister on the bank, and of having nothing to do: once or twice she had peeped into the book her sister was reading.
Chapter two:
There seemed to be no use in waiting by the little door, so she went back to the table,
half hoping she might find another key on it, or at any rate a book of rules for shutting
people up like telescopes
</body></html>
解决方案
推荐阅读
- mongodb - 在 mongodb 聚合框架中展开字典值
- reporting-services - 在图像上叠加文本 SSRS
- audio - 如何修复:device_list:270:找不到声卡(Ubuntu 服务器 18.04)?
- powershell - 如何在所有用户配置文件上获取不同的文件夹名称
- c# - 扩展 Akka.Net
- r - 如何将两个日期子集合并为一列?
- php - db 插入的 Prestashop 产品未显示
- python - 在树莓派 3 上启动时运行两个 python 脚本
- php - sending emails through custom made contact form
- mysql - 移动到 aws 后,CDbConnection 无法打开 DB 连接 Yii