是否可以根据源文档中的存在来包含/排除 XML 处理指令?
我必须从不同的源传回信息,并且可以在两者之间进行转换,但是根据源文档是否有 xml 处理指令,我必须传递它,如果没有,我不应该传递它。
Input
<?xml version="1.0" encoding="UTF-8"?>
<Source/>
Output
<?xml version="1.0" encoding="UTF-8"?>
<Source/>
如果它没有处理指令,我不应该将其包含在输出中,主要是为了支持一些其他不理解它们的遗留程序(废话!)
我可以动态切换样式表并根据输入使用 omit-xml-declaration有说明,但是有没有办法在单个样式表中完成它?
编辑:我无法删除返回数据之前存在的转换。
编辑:我刚刚读到,尽管它看起来像处理指令,但 ,事实上它不是,所以不确定是否可以匹配它,有什么建议吗?
I have to pass back information from a different source and can have a transformation in between, But depending on if the source document has the xml processing instruction, I have to pass it on and if it doesnt, I shouldnt pass it on.
Input
<?xml version="1.0" encoding="UTF-8"?>
<Source/>
Output
<?xml version="1.0" encoding="UTF-8"?>
<Source/>
If it doesnt have the processing instruction, I shouldnt include it in the output, mainly to support some other legacy programs which do not understand them (duh!)
I can dynamically switch stylesheets and use the omit-xml-declaration based on if the input had the instruction, but is there a way to do it in a single stylesheet?
EDIT: I cant remove the transformation that is present prior to returning the data.
EDIT: I just read that even though it looks like a processing instruction, the <?xml version.. ?>
, infact it is not, so not sure if it is possible to match on it, any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
XML 声明看起来像一条处理指令,但事实并非如此。
它的存在是为了通知 XML 解析器它将要读取的文档(XML 版本、字符编码)。
它不存在于生成的 DOM/信息集中,因此无法在 XSLT 中匹配。
此外,您无法动态更改
指令,例如
或
构造将不起作用。我的建议是:如果部分下游应用程序不理解 XML 声明(这是一个
WTF事实,真的让我摸不着头脑),那么就不要使用它们:The XML declaration looks like a processing instruction, but it isn't.
It exists to inform the XML parser about the document that it is going to read (XML version, character encoding).
It does not exist in the resulting DOM/infoset and therefore it cannot be matched in XSLT.
Additionally, you cannot dynamically alter the
<xsl:output>
directive, something like different output elements in an<xsl:if>
or<xsl:choose>
construct won't work.My suggestion is: If part of the downstream applications do not understand XML declarations (which is a
WTFfact that really makes me scratch my head), then leave them off all the time using: