给定一个元素,如何使用 XSLT 确定其类型?
我有一个包含以下类型元素的 XML 架构:
<xs:simpleType name="value">
<xs:union memberTypes="xs:boolean xs:int xs:double xs:string"/>
</xs:simpleType>
示例 XML 片段如下:
<value>42</value>
在 XSLT 转换中,如何确定值的类型,即它是布尔值、整数、双精度值还是字符串?
I have an XML Schema that contains the following type element:
<xs:simpleType name="value">
<xs:union memberTypes="xs:boolean xs:int xs:double xs:string"/>
</xs:simpleType>
A sample XML fragment would be:
<value>42</value>
In an XSLT transform, how do I determine which type the value has, i.e., is it a boolean, an integer, a double, or a string?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果没有与 XML 文档关联的架构,则答案是类型始终为
xs:string
并且这个问题没有太大意义。但是,正确的问题是:这与哪些类型兼容(可转换为)?
此转换显示了如何找出这一点。它还说明了
的优雅和强大功能:应用于提供的 XML 文档时:
想要的、正确的产生结果:
If there isn't a schema associated with the XML document, the answer is that the type is always
xs:string
and the question isn't too meaningful.However, the correct question is: With which of those types is this compatible (castable as) ?
This transformation shows how this can be found out. It also illustrates the elegance and power of
<xsl:next-match>
:when applied on the provided XML document:
the wanted, correct result is produced:
如果您使用架构感知转换,则此值元素的类型将是 xs:int - 实例有效的联合的第一个成员类型。
如果您想测试它是什么类型,请尝试以下操作:
If you are using a schema-aware transform, then this value element will be of type xs:int - the first of the member types of the union against which the instance is valid.
If you want to test which type it is, try something like this: