xsl属性引用在相同的xsl:template作用域中

时间:2015-08-17 19:56:02

标签: java xslt

<xsl:if test="$person/name/first != '' ">
    <xsl:attribute name="FirstName">
        <xsl:value-of select="$person/name/first"/>
    </xsl:attribute>
</xsl:if>
<xsl:if test="$person/name/middle != '' " >
    <xsl:attribute name="MiddleInitial">
        <xsl:variable name="middle" select="$person/name/middle" />
        <xsl:value-of select="substring($middle, 1, 1)"/>
    </xsl:attribute>
</xsl:if>
<xsl:if test="$person/name/last != '' ">
    <xsl:attribute name="LastName">
        <xsl:value-of select="$person/name/last"/>
    </xsl:attribute>
</xsl:if>

如果MiddleInitial值只有1个字符长,我可以执行以下操作:

<xsl: if test="((FirstName != '') and (MiddleInitial != '') and (LastName != ''))">
    <xsl:variable name="fullName" select="normalize-space(concat($FirstName,$MiddleInitial,$LastName))"/>
    <xsl:choose>
        <xsl:when test="string-length($fullName)>30"><xsl:value-of select="substring($fullName,1,30)"/></xsl:when>
        <xsl:otherwise><xsl:value-of select="$fullName"/></xsl:otherwise>
    </xsl:choose>
</xsl:if>

0 个答案:

没有答案