Search

I’m displaying a list of ministry workers from a church ministry team XML file. In my XSL file, I am grouping the folks by group name. Some individuals in this list have two position titles because they are in two different ministry groups. My problem is that I’m unable to display the individual’s position name for that particular group.

For instance, in the XML, you will see my entry at line 258… is listed in groups 09-10 Ministries Team and Ministries Advisory Team. In those two different groups, this person has two different position titles. Since I’m grouping by minstrygroup/@name, I want to display the positionname that corresponds with the group it belongs to. I’m having a heck of time getting this done. Can anyone help?

It seems like the xpath on line 116:

ministrygroups/ministrygroup[@name=$group-name]/positionname

should only produce the positionname you want, but the predicate isn’t filtering correctly. I didn’t dive into all the keys you have in there, but I’m guessing the key you’re using might be causing the problem. Let me know if you’re still having trouble with it tomorrow, I can take a closer look.

The keys were matching on the wrong node. They were matching on <xsl:key name="min-group" match="leader" use="ministrygroups/ministrygroup/@name"/>. It needed to be <xsl:key name="min-group" match="ministrygroup" use="@name"/>. Here’s the adjusted output and XSL below.

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:date="http://exslt.org/dates-and-times" version="1.0" extension-element-prefixes="date">
    <xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes" omit-xml-declaration="yes"/>
    <!-- Removed DOCTYPE PUBLIC and DOCTYPE SYSTEM so it would not display when included. -->
    <xsl:param name="todaysdate" select="translate(substring(date:date-time(),1,10),'-','')"/>
    <xsl:key name="min-group" match="ministrygroup" use="@name"/>

    <xsl:template match="/">
        <xsl:apply-templates select="data/womens-leadership"/>
    </xsl:template>
    <xsl:template match="womens-leadership">

        <!-- Staff -->
        <xsl:apply-templates select="leader/ministrygroups/ministrygroup[count(.|key('min-group', @name)[1]) = 1][contains(groupname, 'Staff')]" mode="group">
            <xsl:sort select="groupname" order="ascending"/>
        </xsl:apply-templates>

        <!-- Ministries Team -->
        <xsl:apply-templates select="leader/ministrygroups/ministrygroup[count(.|key('min-group', @name)[1]) = 1][contains(groupname, 'Ministries Team')]" mode="group">
            <xsl:sort select="groupname" order="ascending"/>
        </xsl:apply-templates>

        <!-- Ministries Advisory Team -->
        <xsl:apply-templates select="leader/ministrygroups/ministrygroup[count(.|key('min-group', @name)[1]) = 1][contains(groupname, 'Ministries Advisory Team')]" mode="group">
            <xsl:sort select="groupname" order="ascending"/>
        </xsl:apply-templates>

        <!-- Bible Studies -->
        <h3>Bible Studies</h3>
        <xsl:apply-templates select="leader/ministrygroups/ministrygroup[count(.|key('min-group', @name)[1]) = 1][not(contains(groupname, 'Ministries Team') or contains(groupname, 'Ministries Advisory Team') or contains(groupname, 'Staff'))]" mode="group">
            <xsl:sort select="groupname" order="ascending"/>
        </xsl:apply-templates>

    </xsl:template>

    <xsl:template match="ministrygroup" mode="group">
        <xsl:param name="group-name" select="@name"/>
        <xsl:param name="position-name" select="positionname"/>
        <xsl:choose>
            <xsl:when test="$group-name='Staff'">
                <h3>
                    <xsl:value-of select="$group-name"/>
                </h3>
                <xsl:apply-templates select="key('min-group', self::node()[$position-name]/@name)[contains(positionname,'Director')]" mode="itemdetail">
                    <xsl:sort select="positionname"/>
                </xsl:apply-templates>
                <xsl:apply-templates select="key('min-group', self::node()[$position-name]/@name)[not(contains(positionname,'Director'))]" mode="itemdetail">
                    <xsl:sort select="../../lastname"/>
                </xsl:apply-templates>
            </xsl:when>
            <xsl:when test="contains($group-name,'Ministries Team')">
                <h3>
                    <xsl:value-of select="$group-name"/>
                </h3>
                <xsl:apply-templates select="key('min-group', self::node()[$position-name]/@name)[contains(positionname,'Moderator')]" mode="itemdetail">
                    <xsl:sort select="positionname" order="ascending"/>
                </xsl:apply-templates>
                <xsl:apply-templates select="key('min-group', self::node()[$position-name]/@name)[not(contains(positionname,'Moderator'))]" mode="itemdetail">
                    <xsl:sort select="positionname" order="ascending"/>
                </xsl:apply-templates>
            </xsl:when>
            <xsl:when test="contains($group-name, 'Ministries Advisory Team')">
                <h3>
                    <xsl:value-of select="$group-name"/>
                </h3>
                <xsl:apply-templates select="key('min-group', self::node()[$position-name]/@name)[contains(positionname,'Moderator')]" mode="itemdetail">
                    <xsl:sort select="positionname" order="descending"/>
                </xsl:apply-templates>
                <xsl:apply-templates select="key('min-group', self::node()[$position-name]/@name)[not(contains(positionname,'Moderator'))]" mode="itemdetail">
                    <xsl:sort select="positionname" order="ascending"/>
                </xsl:apply-templates>
            </xsl:when>
            <xsl:when test="not($group-name='Staff')">
                <h4>
                    <xsl:value-of select="$group-name"/>
                </h4>
                <xsl:apply-templates select="key('min-group', self::node()[$position-name]/@name)[contains($position-name,'Bible')]" mode="itemdetail">
                    <xsl:sort select="positionname" order="descending"/>
                </xsl:apply-templates>
            </xsl:when>
            <xsl:otherwise> </xsl:otherwise>
        </xsl:choose>


    </xsl:template>

    <xsl:template match="ministrygroup" mode="itemdetail">
        <xsl:param name="group-name" select="@name"/>
        <dl class="leaderlisting">
            <dt class="leadername">
                <xsl:value-of select="concat(../../firstname, ' ' , ../../lastname)"/> 
            </dt>
            <xsl:apply-templates select="self::node()[@name=$group-name]" mode="position"/>
        </dl>
    </xsl:template>

    <!-- Apply position names by ministry group -->
    <xsl:template match="ministrygroup" mode="position">
        <xsl:apply-templates select="positionname"/>
    </xsl:template>

    <!-- Get available postion names -->
    <xsl:template match="positionname">
        <dd>
            <xsl:value-of select="."/>
        </dd>
    </xsl:template>

</xsl:stylesheet>

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details