1

I am trying to apply a template using XSLT1 and I can't get it to work:

<xsl:apply-templates select="MeetingWorkBook/Meeting[1]/SpecialEvent/Event[/Date[@AllDayEvent='1']]" mode="FirstRow_Pray">
    <xsl:with-param name="strClass">cellBold borderRight</xsl:with-param>
</xsl:apply-templates>

I am trying to apply this template:

  <!--This is used to insert the Chairman, or Special Event-->
  <xsl:template match="Chairman | Event" mode="FirstRow_Pray">
    <xsl:param name="strClass"/>
    <td class="{$strClass}">
      <xsl:if test="self::Event">
        <xsl:attribute name="rowspan">2</xsl:attribute>
      </xsl:if>
      <xsl:value-of select="."/>
    </td>
  </xsl:template>

But I only want to apply the template if the Event element exists and the sibling Date[@AllDayEvent] is true.

  • I know I can wrap my apply-templates call with if clause first and that would work(see below).

  • I know I can improve the logic of the Event template to test the value of the sibling elements attribute.

I have a lot of templates for using specific Event properties and would prefer the ability the select the item Event where its sibling element Date has a certain attribute value.

But my attempt does not work. I saw this answer and tried:

MeetingWorkBook/Meeting[1]/SpecialEvent/Event[Date[@AllDayEvent='1']]

But it still doesn't work.


This will work:

  <xsl:if test="MeetingWorkBook/Meeting[1]/SpecialEvent/Date[@AllDayEvent='1']">
    <xsl:apply-templates select="MeetingWorkBook/Meeting[1]/SpecialEvent/Event" mode="FirstRow_Pray">
      <xsl:with-param name="strClass">cellBold borderRight</xsl:with-param>
    </xsl:apply-templates>
  </xsl:if>

But I want to avoid needing the if if possible.

I can now see what was wrong with my original attempt. Date is not a child of Event but a sibling.

  • MeetingWorkBook/Meeting[1]/SpecialEvent/Date
  • MeetingWorkBook/Meeting[1]/SpecialEvent/Event

So is it possible to apply a template on Event where the sibling Date has an attribute AllDayEvent with a value of 1. Or do I have no choice but to use the if approach?

Sample XML data:

<Meeting BookmarkId="2" PageBreak="0" NumberClasses="1" SpecialEvent="1" CircuitVisit="0">
    <Date ThisWeek="W20200217" NextWeek="W20200224">February 17-23</Date>
    <WeeklyBibleReading>GENESIS 18-19</WeeklyBibleReading>
    <ReviewQuestion></ReviewQuestion>
    <SpecialEvent>
        <Event>Circuit Assembly - Love Jehovah With All Your Heart</Event>
        <Location>Bristol Assembly Hall, Hortham Lane, Bristol, BS32 4JH</Location>
        <Date Day="23" DayShort="Sun" DayFull="Sunday" Month="2" MonthShort="Feb" MonthFull="February" Year="2020" Memorial="0" AllDayEvent="1" MidweekEvent="1">23/02/2020</Date>
    </SpecialEvent>
</Meeting>
Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164

1 Answers1

1

You should be able to add the predicate to SpecialEvent instead of Event...

<xsl:apply-templates select="MeetingWorkBook/Meeting[1]/SpecialEvent[Date/@AllDayEvent='1']/Event" mode="FirstRow_Pray">
    <xsl:with-param name="strClass">cellBold borderRight</xsl:with-param>
</xsl:apply-templates>
Daniel Haley
  • 51,389
  • 6
  • 69
  • 95