Xml xsl:call模板中的条件,以限制在XSLT中拆分场景中考虑Null或空格

Xml xsl:call模板中的条件,以限制在XSLT中拆分场景中考虑Null或空格,xml,xslt,biztalk,Xml,Xslt,Biztalk,在调用语句xsl:call template之前,我需要执行一个条件。我试图检查一个条件,在拆分字符串后,如果value1或value2有Null或空值,则不应打印整个记录及其内部的元素 以下是我需要的一个简短示例: Value1 : Name1;;Name3 Value2 : Sam;Tsn;Doug 预期产出: <Profile> <Type>Name1</Type> <Value>Sam</Value> </Profil

在调用语句
xsl:call template
之前,我需要执行一个条件。我试图检查一个条件,在拆分字符串后,如果value1或value2有Null或空值,则不应打印整个记录及其内部的元素

以下是我需要的一个简短示例:

Value1 : Name1;;Name3

Value2 : Sam;Tsn;Doug
预期产出:

<Profile>
<Type>Name1</Type>
<Value>Sam</Value>
</Profile>
<Profile>
<Type>Name3</Type>
<Value>Doug</Value>
</Profile>

名称1
山姆
名字3
道格
因此,这里没有打印第二个类型和值,因为它在Value1中有一个空白值 反之亦然,如果Value2的值为空,Value1的值为空,则应限制其打印

我所尝试的: 问题是它总是包含一个值,所以我们不能在那里进行检查

<xsl:template name="WritePropertyNodeTemplateName">
<xsl:param name="Name" />
<xsl:param name="Type" />
<xsl:if test="$Name != '' and $Type != ''"> // Had put condition here but didnt work
    <xsl:call-template name="StringSplitName">
        <xsl:with-param name="val1" select="$Name" />
        <xsl:with-param name="val2" select="$Type" />
    </xsl:call-template>
</xsl:if>
</xsl:template>
<xsl:template name="StringSplitName">
<xsl:param name="val1" />
<xsl:param name="val2" />
<xsl:choose>
    <xsl:when test="contains($val1, ';')">
        <xsl:if test="$val2 != '' and $val1 != ''">
            <xsl:value-of select="'1st'" />
            <ns1:OtherType xmlns:ns1="http://schemas.datacontract.org/2004/07/GEP.Cumulus.WebInterfaces.BusinessEntities">
                <ns1:Name xmlns:ns1="http://schemas.datacontract.org/2004/07/GEP.Cumulus.WebInterfaces.BusinessEntities">
                    <xsl:value-of select="substring-before($val1, ';')" />
                </ns1:Name>
                <ns1:Type xmlns:ns1="http://schemas.datacontract.org/2004/07/GEP.Cumulus.WebInterfaces.BusinessEntities">
                    <xsl:value-of select="substring-before($val2, ';')" />
                </ns1:Type>
            </ns1:OtherType>
            <xsl:call-template name="StringSplitName">
                 //Tried to put condition here also but didnt work
                <xsl:with-param name="val1" select="substring-after($val1, ';')" />
                <xsl:with-param name="val2" select="substring-after($val2, ';')" />
            </xsl:call-template>
        </xsl:if>
    </xsl:when>
</xsl:choose>
</xsl:template>

//我把条件放在这里,但不起作用
//试图把条件也放在这里,但没有起作用

我正在BizTalk映射中使用此XSLT代码

你为什么不简单地:

<xsl:template name="tokenize">
    <xsl:param name="types"/>
    <xsl:param name="values"/>
    <xsl:param name="delimiter" select="';'"/>
        <xsl:variable name="type" select="substring-before(concat($types, $delimiter), $delimiter)" />
        <xsl:variable name="value" select="substring-before(concat($values, $delimiter), $delimiter)" />
        <xsl:if test="normalize-space($type) and normalize-space($value)">
            <Profile>
                <Type>
                    <xsl:value-of select="$type"/>
                </Type>
                <Value>
                    <xsl:value-of select="$value"/>
                </Value>
            </Profile>
        </xsl:if>
        <xsl:if test="contains($types, $delimiter)">
            <!-- recursive call -->
            <xsl:call-template name="tokenize">
                <xsl:with-param name="types" select="substring-after($types, $delimiter)"/>
                <xsl:with-param name="values" select="substring-after($values, $delimiter)"/>
            </xsl:call-template>
        </xsl:if>
</xsl:template>

呼叫示例:

    <xsl:call-template name="tokenize">
        <xsl:with-param name="types">Name1;  ;Name3</xsl:with-param>
        <xsl:with-param name="values">Sam;Tsn;Doug;</xsl:with-param>
    </xsl:call-template>

姓名1;名字3
山姆;Tsn;道格;
结果:

  <Profile>
    <Type>Name1</Type>
    <Value>Sam</Value>
  </Profile>
  <Profile>
    <Type>Name3</Type>
    <Value>Doug</Value>
  </Profile>

名称1
山姆
名字3
道格


演示:

谢谢您的回答,但此解决方案仅适用于空白或空条件。那么value2中的条件是否具有值“Tsn”,如果是值Tsn,则不应打印。@学习者我在您的问题中没有提到此类条件,因此我自然没有提及它。无论如何,在现有条件上添加任何条件都应该很容易。谢谢你的帮助,我只是想知道这就是为什么我问这个问题。谢谢你的帮助,非常感谢你抽出时间来做这件事。