gpt4 book ai didi

xml - xsl :strip-space is not removing the carriage return

转载 作者:数据小太阳 更新时间:2023-10-29 01:58:07 24 4
gpt4 key购买 nike

这是 xml 文件。 “CategoryName”元素中的空格和回车是有意的。

<?xml version="1.0" encoding="utf-8"?>
<group>
<item>
<id>item 1</id>
<CategoryName>


</CategoryName>
</item>
<item>
<id>item 2</id>
<CategoryName></CategoryName>
</item>
<item>
<id>item 3</id>
<CategoryName> </CategoryName>
</item>

</group>

以下是上述 XML 文件的 XSLT 文件。它应该做的是清除“CategoryName”元素中的所有空白区域。然后,它将测试“CategoryName”是否为空。

<?xml version="1.0" encoding="utf-8"?>
<!-- DWXMLSource="testempty.xml" -->

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="utf-8" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/>

<xsl:strip-space elements="*" /> <!--HERE IS STRIP SPACE-->


<xsl:template match="/">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Untitled Document</title>
</head>

<body>
<xsl:for-each select="/group/item">
<xsl:if test="CategoryName = ''"> <!--HERE IS THE TEST-->
<p>Empty</p> <!--IT WILL OUTPUT 'EMPTY' IF THE ELEMENT IS EMPTY-->
</xsl:if>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

问题是,xsl:strip-space 没有发挥作用。只有项目 2 的“CategoryName”通过了“空”测试。

怎么了?

最佳答案

我不知道 Dreamweaver 使用的是什么 XSLT 引擎,但这看起来不对。

我认为可能有一些 XSLT 处理器只在您向它们提供未解析的输入(词法 XML)时才应用 xsl:strip-space,而在您向它们提供 DOM 时则不会。规范中没有任何内容可以证明这种行为是合理的,但它使实现者的生活变得更加轻松。

然而,值得指出的是,这不是 xsl:strip-space 的预期使用方式。它旨在用于去除“可忽略的”空白,即用于在纯元素内容中缩进的空白。如果您使用的是 XSLT 2.0 模式感知转换,这将成为规则:xsl:strip-space 不会影响具有简单内容的元素的内容。这是因为去除此类元素的空格可能会使该元素对架构无效。

关于xml - xsl :strip-space is not removing the carriage return,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14050522/

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