xslt - 如何获取值类型
问题描述
请教我。
有没有办法获取您指定的变量的类型?例如,我正在考虑使用获取类型并将其输出到消息中,或者比较类型以生成如下条件。
或者有可能做到吗?
<!-- example -->
<xsl:message select="[get_type_function]([any_variable_as_string])" />
<!-- message -->
xs:string
此致。
解决方案
你期望变量的类型是什么,如果是声明<xsl:variable name="var1" as="item()*" select="1"/>
,是你想要的类型,然后是声明的item()*
或者是它xs:integer
还是xs:integer*
?在 XSLT 1 和 EXSLT 的上下文中,有http://exslt.org/exsl/functions/object-type/index.html来获取基本类型'string', 'number', 'boolean', 'node-set', 'RTF' or 'external'
,但是 XSLT/XPath 1 有一个相当简单的类型系统并且没有无论如何声明类型,在 XSLT/XPath 2 或 3 中,类型系统要复杂得多。
在 Saxon 9 EE 或 PE 的上下文中,有http://saxonica.com/html/documentation/functions/saxon/type.html所以对于上面的示例
<xsl:variable name="var1" as="item()*" select="1"/>
<xsl:message select="saxon:type($var1)('name')" xmlns:saxon="http://saxon.sf.net/"/>
<xsl:variable name="var2" as="item()*" select="'foo'"/>
<xsl:message select="saxon:type($var2)('name')" xmlns:saxon="http://saxon.sf.net/"/>
你得到
integer
string
但我不确定您将如何获得适合异构序列的类型
<xsl:variable name="var3" as="item()*" select="1, 'foo'"/>
<xsl:message select="saxon:type($var3)('name')" xmlns:saxon="http://saxon.sf.net/"/>
也简单地给出整数。
推荐阅读
- matlab - 在 Matlab 中检查文件是函数还是脚本
- javascript - 改变对象以将值排序为数组中的键
- visual-studio - 有没有办法以不同的用户身份在 Visual Studio 中运行 selenium?
- c++11 - 关于 Lambda 与 boost::adaptors::filtered() 一起使用的两个问题
- javascript - 如何定位 React 中的特定元素?
- wcf - 服务证书 WCF 服务
- git - .gitattributes 中的文件扩展
- python - Scipy的csr_matrix按值排序?
- asp.net-core - 我的应用程序(在 Docker 容器中)如何访问 MongoDb(在我的主机上)?
- latex - 去掉标题页Latex的背景图片