Using XSLT, how can I increase the value of the 'format' attribute of a & lt; xsl: number & gt; (eg 'a' + 1 = 'b')?

advertisements

There are 2321 occurrences of the character 'a' in the element contents of my source XML file.

I have succeeded in obtaining this number, but I can only do it for the 'a' character. I need to obtain the occurrences for all the letters of the alphabet.

See code:

This is used to print out a TextBlock element:

<xsl:template name="get-textblock">

    <xsl:param name="letter-one"/>
    <xsl:param name="letter-two"/>
    <xsl:param name="letter-one-f"/>
    <xsl:param name="letter-two-f"/>

    <xsl:if test="$letter-one">
        <xsl:number value="$letter-one" format="$letter-one-f"/>
    </xsl:if>

    <xsl:if test="$letter-two">
        <xsl:number value="$letter-two" format="$letter-two-f"/>
    </xsl:if>

</xsl:template>

Then, in this recursive loop I print out how many times 'a' or 'A' occur, using an XPath expression and the get-textblock template.

<xsl:template name="print-alphabet-value-rows">
    <!-- 'letter' is just a counter. -->
    <xsl:param name="letter" select="1"/>
    <!-- numbers -->
    <xsl:param name="letter-one" select="1"/>
    <xsl:param name="letter-two" select="1"/>
    <!-- format attribute values -->
    <xsl:param name="letter-one-f" select=" 'a' "/>
    <xsl:param name="letter-two-f" select=" 'A' "/>
    <xsl:param name="gridrow">2</xsl:param>
    <xsl:param name="gridcol">2</xsl:param>

    <xsl:call-template name="get-textblock">
        <xsl:with-param name="gridrow" select="$gridrow"/>
        <xsl:with-param name="gridcol" select="$gridcol"/>
        <xsl:with-param name="style">{StaticResource ValueText}</xsl:with-param>
        <xsl:with-param name="letter-one-f" select="$letter-one-f"/>
        <xsl:with-param name="letter-two-f" select="$letter-two-f"/>
        <xsl:with-param name="letter-one" select="$letter-one"/>
        <xsl:with-param name="letter-two" select="$letter-two"/>
        <xsl:with-param name="text">
            <xsl:value-of select="count(/n-grams-sorted/n-gram[starts-with(.,$letter-one-f) or starts-with(.,$letter-two-f) ])"/>
        </xsl:with-param>
    </xsl:call-template>

    <xsl:if test="$letter &lt; 26">
        <xsl:call-template name="print-alphabet-value-rows">
            <xsl:with-param name="gridrow" select="$gridrow + 1"/>
            <xsl:with-param name="letter" select="$letter +1"/>
            <!-- this doesn't work. It prints out the same number of occurrences for all the rows because it only fetches 'a' and 'A', it never increases them -->
            <xsl:with-param name="letter-one" select="$letter-one +1"/>
            <xsl:with-param name="letter-two" select="$letter-two +1"/>
        </xsl:call-template>
    </xsl:if>

So, what I do here is I define a get-textblock template to draw a TextBlock element. Then, I supply the following parameters:

letter: a counter to simply go 26 rows down

letter-one: a number which has a format 'a' attached to it

letter-two: a number which has a format 'A' attached to it

What I want to do is keep increasing 'a' and 'A', so that the corresponding XPath expression reads 'b' & 'B', 'c' & 'C' etc., all the way down to the last letter of the alphabet. I don't know to accomplish that.

Any ideas? Thanks


I'm not totally sure I understand the question, but can you do anything with something like

translate($letter-one, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ','bcdefghijklmnopqrstuvwxyzaBCDEFGHIJKLMNOPQRSTUVWXYZA')