XSLT 验证和连接多个变量 [英] XSLT Validate and Concatenate Multiple Variables

查看:23
本文介绍了XSLT 验证和连接多个变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

验证后我必须验证和连接多个变量.

<xsl:variable name="val2" select="//xpath"/><xsl:variable name="val3" select="//xpath"/><xsl:variable name="val4" select="//xpath"/><xsl:variable name="val5" select="//xpath"/>

是否有任何可用的模板或任何人都可以帮助我这样做.

评论更新

我想连接五个这样的值:Address、Address1、City、State、Zipcode.如果 Address 缺失,我会得到这样的输出, address1, city, state, zipcode".我想去掉第一个逗号.

<xsl:variable name="__add" select="translate(///*/text()[contains(., 'Address')]/following::td[contains(@class, 'fnt')][1], ',', '')"/><xsl:变量名=地址"><xsl:for-each select="$__add |//*/text()[contains(., 'City')]/following::td[contains(@class, 'fnt')][1] |//*/text()[contains(., 'State')]/following::td[contains(@class, 'fnt')][1] |//*/text()[contains(., 'Pincode')]/following::td[contains(@class, 'fnt')][1]"><xsl:value-of select="concat(substring(', ', 1 div (position()!=1)), .)"/></xsl:for-each></xsl:变量>

解决方案

在 XSLT 2.0 中:string-join((Address, Address1, City, State, Zipcode), ',')>

在 XSLT 1.0 中,假设您按文档顺序输出结果:

<xsl:if test="position() != 1">, </xsl:if><xsl:value-of select="."/></xsl:for-each>

如果不是按照文档顺序,那么就像 XSLT 1.0 中的许多东西一样,它可能会相当乏味.

I have to validate and concatenate multiple variable after validating them.

<xsl:variable name="val1" select="//xpath"/>
<xsl:variable name="val2" select="//xpath"/>
<xsl:variable name="val3" select="//xpath"/>
<xsl:variable name="val4" select="//xpath"/>
<xsl:variable name="val5" select="//xpath"/>

Is there any template available for this or anyone can help me doing this.

Update from comments

I want to concatenate five values like this: Address, Address1, City, State, Zipcode. If Address is missing I'll get an output like this ", address1, city, state, zipcode". I want to get rid of that first comma.

<xsl:variable name="__add" select="translate(//*/text()[contains(., 'Address')]/following::td[contains(@class, 'fnt')][1], ',', '')"/>

<xsl:variable name="address">
    <xsl:for-each select="$__add | //*/text()[contains(., 'City')]/following::td[contains(@class, 'fnt')][1] | //*/text()[contains(., 'State')]/following::td[contains(@class, 'fnt')][1] | //*/text()[contains(., 'Pincode')]/following::td[contains(@class, 'fnt')][1]">
        <xsl:value-of select="concat(substring(', ', 1 div (position()!=1)), .)"/>
    </xsl:for-each>
</xsl:variable>

解决方案

In XSLT 2.0: string-join((Address, Address1, City, State, Zipcode), ',')

In XSLT 1.0, provided you're outputting the results in document order:

<xsl:for-each select="Address | Address1 | City | State | Zipcode">
  <xsl:if test="position() != 1">, </xsl:if>
  <xsl:value-of select="."/>
</xsl:for-each>

If not in document order, then like many things in XSLT 1.0, it's probably rather tedious.

这篇关于XSLT 验证和连接多个变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆