基于奇偶的XSLT转换
我想通过XSLT将下面逗号分隔的列表转换为基于奇偶位置的下面输出 输入-基于奇偶的XSLT转换,xslt,Xslt,我想通过XSLT将下面逗号分隔的列表转换为基于奇偶位置的下面输出 输入- field1,value1,field2,value2,field3,value3 输出- <root> <field1>value1</field1> <field2>value2</field2> <field3>value3</field3> </root> 价值1 价值2 价值3 提前谢谢 问候 Nilay您可以
field1,value1,field2,value2,field3,value3
输出-
<root>
<field1>value1</field1>
<field2>value2</field2>
<field3>value3</field3>
</root>
价值1
价值2
价值3
提前谢谢
问候
Nilay您可以使用递归模板调用,而无需使用扩展函数 XSLT1.0
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:param name="input" select="'field1,value1,field2,value2,field3,value3'"/>
<xsl:template match="/">
<root>
<xsl:call-template name="process">
<xsl:with-param name="toProcess" select="$input"/>
</xsl:call-template>
</root>
</xsl:template>
<xsl:template name="process">
<xsl:param name="toProcess"/>
<xsl:variable name="name" select="normalize-space(substring-before($toProcess,','))"/>
<xsl:variable name="value" select="normalize-space(substring-before(
concat(substring-after($toProcess,','),',')
,','))"/>
<xsl:variable name="remaining" select="substring-after(
substring-after($toProcess,',')
,',')"/>
<xsl:element name="{$name}">
<xsl:value-of select="$value"/>
</xsl:element>
<xsl:if test="string($remaining)">
<xsl:call-template name="process">
<xsl:with-param name="toProcess" select="$remaining"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
输出(使用任何格式良好的XML输入。)
价值1
价值2
价值3
您使用/可以使用哪个XSLT处理器和哪个XSLT版本?使用tokenize('field1,value1,field2,value2,field3,value3',')[position()mod 2=0]
,在XSLT 2.0中很容易解决这个问题。XSLT 1.0处理器是哪个XSLT 1.0处理器?您是否支持?我正在TIBCO中使用XSLT。我想他们支持tokenize。谢谢你的回复。
<root>
<field1>value1</field1>
<field2>value2</field2>
<field3>value3</field3>
</root>