XSL中的条件:呼叫网板,以限制考虑XSLT中拆分方案的空格或空格



我需要在调用语句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>

因此,这里的第二种类型和值未打印,因为它在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>

结果:

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

演示:http://xsltransform.net/93dehfw

最新更新