gpt4 book ai didi

xml - XSLT 副本不保留空格

转载 作者:行者123 更新时间:2023-12-04 05:02:00 27 4
gpt4 key购买 nike

在使用 xsl:copy-of 转换以下 xml 时 - 我的转换丢失了原始文档的格式 - 我根本不希望它接触原始文档。从字面上看只是复制节点 - 原封不动

源 XML

  <flow>
<flow>
<material><mattext fontface="Arial"><p style="white-space: pre-wrap"><font size="11">The moon is the only extraterrestrial body to be visited by humans?</font></p></mattext>
</material>
</flow>

我得到这个结果
<flow><flow><material><mattext fontface="Arial" texttype="text/plain"><p style="white-space: pre-wrap"><font size="11">The moon is the only extraterrestrial body to be visited by humans?</font></p></mattext></material></flow>

正如你所看到的,它把所有内容都放在一行上 - 为了我的目的,我需要保留空格( pretty-print 不是一种选择)

我的 XSL 看起来像这样
<xsl:for-each-group select="qti:item" group-adjacent="(position()-1)">

<!-- Output the file-->
<xsl:result-document href="{$filename}">
<questtag>
<!-- Output the contents-->
<xsl:copy-of select="current-group()"/>
</questtag>
</xsl:result-document>
</xsl:for-each-group>

更新:好的 - 我发现如果我删除源文件 DTD 则保留空格 - 但这不是解决方案的选项

最佳答案

XSLT 2.0 指出,当源文件是从 DTD 或模式验证的文档构建的时,纯元素内容中的空白在到达 XSLT 处理器之前会被忽略/去除。所以在 XSLT 看到它时没有空格。如果您希望空格很重要,则需要将内容模型声明为混合内容。

关于xml - XSLT 副本不保留空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16042854/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com