Vishakh .K.V
Vishakh .K.V

Reputation: 25

Is it possible to replace string with * in xsl 1.0

I am using following template to print some data

<xsl:template name="AgeGroupTotalHiddenHeader">
    <tr style='visibility:collapse'>
        <xsl:for-each select="child::SubDetailBody/SubDetailHeader">
            <xsl:if test="name(.) = 'SubDetailHeader' and @beanType='AGE_DATA'">
                <xsl:for-each select="Label">
                    <td align="center" class="txtsmall3">
                        <xsl:value-of select="@textLabel" />
                    </td>
                </xsl:for-each>
            </xsl:if>
        </xsl:for-each>
    </tr>
</xsl:template>

I want value of @textLabel to be replaced with * sign, that is if the string is 'abcde' it should be printed as ***** (length of 'abcde' = 5 so there should be 5 stars). Is this possible ? can anyone please help?

Upvotes: 0

Views: 53

Answers (1)

michael.hor257k
michael.hor257k

Reputation: 117140

If you know the maximum possible length of the input string, you could use:

<xsl:value-of select="substring('*********************', 1, string-length($input))"/>

If you know in advance all possible characters that the input string can contain, you could do something like:

<xsl:value-of select="translate($input, 'abcdefgh', '********')"/>

(make sure the number of characters in the 2nd and 3rd parameter is the same).

If neither assumption is true, then it gets more complicated.


Side note: if this is related to security, you should be aware that knowing the length of an obscured string may be valuable to the attacker.

Upvotes: 1

Related Questions