0

I am very new in my role with no XML experience at all, and we are encountering a problem with our employee directory where someone's last name starts with a lowercase letter, and is not being displayed in the correct letter list. My predecessor made separate pages for each letter of the alphabet, and it is set up to automatically pull employee names in based on what their last name begins with from an existing data feed. Unfortunately, this is only targeted toward names that start with an uppercase letter. The code that exists for each "letter" is below:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" extension-element-prefixes="faculty" version="1.0" xmlns:faculty="ext1" xmlns:xalan="http://xml.apache.org/xalan">
    <xsl:output encoding="UTF-8" indent="yes" method="html" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"/>
        <xsl:include href="/_internal/formats/EmpDir/EmpDir.xsl"/>
        <xsl:param name="alphaValue">v</xsl:param>
        <xsl:template match="/">
            <xsl:call-template name="Employees">
                <xsl:with-param name="alphaValue"/>
            </xsl:call-template>
        </xsl:template>
        <xsl:param name="alphaValue">V</xsl:param>
        <xsl:template match="/">
            <xsl:call-template name="Employees">
                <xsl:with-param name="alphaValue"/>
            </xsl:call-template>
        </xsl:template>
    </xsl:stylesheet>

Because of how the CMS works, I cannot change alphaValue in any way, so I was hoping there was some way to make a catch all for both uppercase and lowercase "V"s that would allow the names to be pulled in together.

The other linked format for EmpDir does have code that seems to catch uppercase and lowercase letters, and this person's name does pull in for the big "A-Z" list, I think it is the part where variables are set to uppercase and lowercase, but I'm not sure which line is the one that allows both to display together on the page. `

<xsl:choose>
                <xsl:when test="count(//directory[starts-with(last, $alphaValue)]) &gt; 0">
                    <p style="text-align: center;">There are = 
                        <xsl:value-of select="count(//directory[starts-with(last, $alphaValue)])"/> entries. 
                    </p>
                    <div style="float:right; width: calc(100% - 40px);">
                        <xsl:for-each select="//directory[starts-with(last, $alphaValue)]">
                            <xsl:sort order="ascending" select="last"/>
                            <xsl:sort order="ascending" select="first"/>
                            <xsl:variable name="lowercase" select="'abcdefghijklmnopqrstuvwxyz'"/>
                            <xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
                            <xsl:variable name="Photo">
                                <xsl:value-of select="translate(nmcid, $uppercase, $lowercase)"/>
                                <xsl:text>.jpg</xsl:text>
                            </xsl:variable>

`

I've tried adding in the following code snippets to no avail:

Hoped this would select both cases and translate/convert to lowercase

<!--add variables for upper and lower case to translate to lowercase -->
<xsl:variable name="lowercaseV" select="'v'"/>
<xsl:variable name="uppercaseV" select="'V'"/>
<xsl:variable name="alphaValue" select="translate(., $uppercaseV, $lowercaseV)"/>

hoped adding second param would catch the little v

<!--add secondary param for little v-->
<xsl:param name="alphaValue">v</xsl:param>

Neither of these did anything, probably because I don't fully understand how it's set up, but I am at a loss for what to do so that employees with last names like "deAngelo" or "Devine" can appear in the same auto-generated list.

katprohas
  • 1
  • 1
  • The stylesheet you show makes very little sense. You have 2 templates matching `/`. Only the last one will be executed. And redefining the `alphaValue` parameter should produce an error. – michael.hor257k Aug 01 '23 at 22:59
  • @michael.hor257k it has to do with how the CMS is setup, what exists does work as it's written, but it's scattered through various "blocks" in the CMS, which is why I'm struggling to get it fixed. – katprohas Aug 02 '23 at 13:25
  • I believe it has nothing to do with how the CMS is set up. An XSLT processor gets an XML input and processes it according to the instructions in the XSLT stylesheet. The stylesheet you show us is very poorly written and, as I said, you are lucky your processor does not throw an error. I would advise you to rewrite the whole thing - but before you do that (1) identify your processor and (2) get the raw XML input so that you know what you're working with. – michael.hor257k Aug 02 '23 at 14:12
  • I appreciate the tips and additional information. I believe the CMS does the XML processing itself, at least based on what the vendor's support site says, but the previous person had code everywhere so I'll need to do more digging. – katprohas Aug 02 '23 at 18:19
  • It's likely that the CMS **initiates** the XSL process. It is not likely it performs it by itself. As I said, your fist step should be identify the processor - see: https://stackoverflow.com/a/25245033/3016153. – michael.hor257k Aug 02 '23 at 21:25

1 Answers1

0

It is difficult to advise without being able to reproduce the problem (see: minimal reproducible example).

Try replacing this part:

//directory[starts-with(last, $alphaValue)]

with:

//directory[starts-with(translate(last, $lowercase, $uppercase), $alphaValue)]

in all places where it appears (you will probably have to move the 2 variables up in the tree in order to make them visible to all these expressions).

Note that this will still leave out names that start with accented characters.

michael.hor257k
  • 113,275
  • 6
  • 33
  • 51
  • Okay, I did try the code you suggested in the EmpDir sheet, but it didn't make any different in the "V" sheet. Do you think I could something similar like you suggested but for the parameter value declared in the V sheet? – katprohas Aug 02 '23 at 13:40
  • I don't think so, but as I said I don't see the entire picture here. – michael.hor257k Aug 02 '23 at 14:13