• Code Snippet

    By Vedrana M 2 decades ago

    As I found this project to be very useful, I'd like to say thanks by providing some additional code. I hope someone will find it useful. It's not the greatest code in the world (I'm an XML newbie), but it does what I want it to do.

    And btw, I'm also an OpenNTF newbie, so that's why I'm posting this here and not doing something more advanced with it (like CodeBin, I think).



    I tried to format XML views with CSS only, no direct formating with STYLE = ".." in the code. To achieve this, I used classes for different types of columns, mainly for categorized columns. I used the getPositionLevelCount template and iLevelCount variable to generate class names for different category levels, but I ran into a problem with "artificial" categories, the ones generated by concatenating values using "\" in the formula. They belong to the same column, but their iLevelCount values are not the same. For example: AA\BB - AA's level count is 1 and BB's is 2, so they would have different class names. I wanted these types of values to have the same formatting, so I had to find a way to mark all the values in the same column as having the same level. In that case, both AA and BB would have the same level. (Am I making any sense here?)



    To achieve this, I used this template in the xsl_DominoView_StandardTemplates.xsl file:



    <xsl:template name="getCategoryLevelCount">

    <xsl:param name='iCatLevelCount' select='0'/>

    &lt;xsl:param name='sCurPosition'/&gt;<br/>
    



    <!– the last dot in the position (eg. for 2.1.3.4 it would be 6) - used to get the position of the "parent" element in the view –>

    <xsl:variable name="iLastDot">

            &lt;xsl:call-template name='getLastIndexOf'&gt;<br/>
                &lt;xsl:with-param name='str' select=&quot;$sCurPosition&quot;/&gt;<br/>
                &lt;xsl:with-param name='delim' select=&quot;'.'&quot;/&gt;<br/>
            &lt;/xsl:call-template&gt;<br/>
    

    </xsl:variable>

    <xsl:variable name="length">

    &lt;xsl:choose&gt;<br/>
        &lt;xsl:when test=&quot;$iLastDot = 0&quot;&gt;<br/>
                    &lt;xsl:value-of select=&quot;0&quot;/&gt;<br/>
        &lt;/xsl:when&gt;<br/>
        &lt;xsl:otherwise&gt;<br/>
                     &lt;xsl:value-of select=&quot;number($iLastDot - 1)&quot;/&gt;<br/>
        &lt;/xsl:otherwise&gt;<br/>
    &lt;/xsl:choose&gt;<br/>
    

    </xsl:variable>



    <!– position of the "parent" element - eg. for element 2.1.3.4 the parent element is 2.1.3 –>

    <xsl:variable name="sParentPosition" select="substring($sCurPosition, 1, $length)"/>



    <xsl:choose>

    &lt;xsl:when test=&quot;key('keyViewEntries', $sCurPosition)/entrydata[@indent]&quot;&gt; &lt;!-- artificial category (&quot;val1\\val2&quot;) - this is the &quot;val2&quot; part --&gt;<br/>
        &lt;!-- artificial cat --&gt;<br/>
        &lt;xsl:call-template name=&quot;getCategoryLevelCount&quot;&gt;<br/>
            &lt;xsl:with-param name=&quot;sCurPosition&quot; select=&quot;$sParentPosition&quot;/&gt;<br/>
            &lt;xsl:with-param name=&quot;iCatLevelCount&quot; select=&quot;$iCatLevelCount&quot;/&gt;<br/>
        &lt;/xsl:call-template&gt;<br/>
    &lt;/xsl:when&gt;<br/>
    &lt;xsl:when test=&quot;key('keyViewEntries', $sCurPosition)/entrydata[not(@indent)]&quot;&gt; &lt;!-- from &quot;val1\\val2&quot; example - this is &quot;val1&quot;  --&gt;<br/>
        &lt;xsl:choose&gt;<br/>
        &lt;xsl:when test=&quot;string-length($sParentPosition) &amp;gt; 0&quot;&gt;<br/>
            &lt;!-- true cat --&gt;<br/>
            &lt;xsl:call-template name=&quot;getCategoryLevelCount&quot;&gt;<br/>
                &lt;xsl:with-param name=&quot;sCurPosition&quot; select=&quot;$sParentPosition&quot;/&gt;<br/>
                &lt;xsl:with-param name=&quot;iCatLevelCount&quot; select=&quot;$iCatLevelCount + 1&quot;/&gt;<br/>
            &lt;/xsl:call-template&gt;<br/>
        &lt;/xsl:when&gt;<br/>
        &lt;xsl:otherwise&gt;   &lt;!-- first tier category --&gt;<br/>
            &lt;!-- first (true) cat --&gt;<br/>
            &lt;xsl:value-of select=&quot;$iCatLevelCount + 1&quot;/&gt;<br/>
        &lt;/xsl:otherwise&gt;<br/>
        &lt;/xsl:choose&gt;<br/>
    &lt;/xsl:when&gt;<br/>
    

    </xsl:choose>

    </xsl:template>



    And here's the code for getLastIndexOf:

    <xsl:template name="getLastIndexOf">

    <xsl:param name="str"/>

    <xsl:param name="delim"/>

    <xsl:param name="index" select="0"/>

    <xsl:choose>

    &lt;xsl:when test=&quot;contains($str,$delim)&quot;&gt;<br/>
        &lt;xsl:call-template name=&quot;getLastIndexOf&quot;&gt;<br/>
          &lt;xsl:with-param name=&quot;str&quot; select=&quot;substring-after($str,$delim)&quot;/&gt;<br/>
          &lt;xsl:with-param name=&quot;delim&quot; select=&quot;$delim&quot;/&gt;<br/>
          &lt;xsl:with-param name=&quot;index&quot; select=&quot;$index+string-length(substring-before($str,$delim))+1&quot;/&gt;<br/>
        &lt;/xsl:call-template&gt;<br/>
    

    </xsl:when>

    <xsl:otherwise>

    &lt;xsl:value-of select=&quot;$index&quot;/&gt;<br/>
    

    </xsl:otherwise>

    </xsl:choose>

    </xsl:template>