xml – 在xslt中创建数组
发布时间:2020-12-16 08:03:37 所属栏目:百科 来源:网络整理
导读:可以在xslt中创建和使用数组吗?如果有适合的在线示例在线学习?如果不是有办法以模拟数组的方式存储值吗? 使用XSLT 2.0,您可以对所需的任何数据类型进行建模。 例如: xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xs
可以在xslt中创建和使用数组吗?如果有适合的在线示例在线学习?如果不是有办法以模拟数组的方式存储值吗?
使用XSLT 2.0,您可以对所需的任何数据类型进行建模。
例如: <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text" omit-xml-declaration="yes"/> <xsl:variable name="array" as="element()*"> <Item>A</Item> <Item>B</Item> <Item>C</Item> </xsl:variable> <xsl:template match="/"> <xsl:value-of select="$array[2]"/> </xsl:template> </xsl:stylesheet> 有任何输入,输出: B 在XSLT 1.0中,没有Temporaly Result Tree数据类型。存在不允许节点集运算符的结果树片段数据类型。所以,唯一的方法是使用扩展功能:在这种情况下,来自EXSLT(MSXSL具有内置的node-set()扩展)的node-set()也是)。 因此,在没有扩展的XSLT 1.0中,您只能使用内联数据模型,或通过params或外部文档。例如: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text" omit-xml-declaration="yes"/> <xsl:variable name="inline-array"> <Item>A</Item> <Item>B</Item> <Item>C</Item> </xsl:variable> <xsl:param name="array" select="document('')/*/xsl:variable[@name='inline-array']/*"/> <xsl:template match="/"> <xsl:value-of select="$array[2]"/> </xsl:template> </xsl:stylesheet> 结果,任何输入: B 只要你想,我可以提供一个XSLT 1.0加扩展示例(这不是标准的…) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |