I have the following nodeset generated:

Code:
<AccountIdle1>
        <From/>
        <To../>
        <instance src-dn="cn=aaa2,ou=users,o=bca">
          <attr attr-name="givenName">
            <value>AAA</value>
          </attr>
          <attr attr-name="bcaEconOperatorDN">
            <value>cn=VAT131063188,ou=econoperators,o=bca</value>
          </attr>
          <attr attr-name="sn">
            <value>Two</value>
          </attr>
          <attr attr-name="mail">
            <value>aaa2@something.com</value>
          </attr>
          <attr attr-name="title">
            <value>5555</value>
          </attr>
          <instance src-dn="cn=aaa1,ou=users,o=bca">
            <attr attr-name="mail">
              <value>aaa1@something.com</value>
            </attr>
          </instance>
        </instance>
        <instance src-dn="cn=msimeonov,ou=users,o=bca">
          <attr attr-name="givenName">
            <value>Милко</value>
          </attr>
          <attr attr-name="bcaEconOperatorDN">
            <value>cn=EIK200417978,ou=econoperators,o=bca</value>
          </attr>
          <attr attr-name="sn">
            <value>Симеонов</value>
          </attr>
          <attr attr-name="mail">
            <value>msimeonov@something.com</value>
          </attr>
          <attr attr-name="title">
            <value>5555</value>
          </attr>
          <instance src-dn="cn=test01,ou=users,o=bca">
            <attr attr-name="mail">
              <value>info@something.com</value>
            </attr>
          </instance>
          <instance src-dn="cn=bbb1,ou=users,o=bca">
            <attr attr-name="mail">
              <value>bbb1@something.com</value>
            </attr>
          </instance>
          <instance src-dn="cn=bpopov,ou=users,o=bca">
            <attr attr-name="mail">
              <value>solutions@something.com</value>
            </attr>
          </instance>
        </instance>
      </AccountIdle1>
As some may recognize, it comes from a modified version of one of the policies from the PWNotify driver.

Now, I need to generate and send some emails with certain information. From the above example:

- I need to send an email to aaa1@something.com stating that user aaa2 has done something.

- I need to send an email to solutions@something.com stating that user msimeonov has done something.
- I need to send an email to info@something.com stating that user msimeonov has done something.
- I need to send an email to bbb1@something.com stating that user msimeonov has done something.

Here's the rule I'm using:

Code:
<rule>
		<description>bca Send Notifications to Superusers - dev</description>
		<comment xml:space="preserve">Send a notification to all Superusers.</comment>
		<comment name="author" xml:space="preserve">Lothar Haeger</comment>
		<conditions>
			<and>
				<if-global-variable mode="nocase" name="AccountIdle1Superuser" op="equal">true</if-global-variable>
				<if-xpath op="true">count(AccountIdle1/instance)>0</if-xpath>
			</and>
		</conditions>
		<actions>
			<do-for-each>
				<arg-node-set>
					<token-xpath expression="AccountIdle1/instance/instance/attr[@attr-name='mail']/value"/>
				</arg-node-set>
				<arg-actions>
					<do-trace-message color="white" level="3">
						<arg-string>
							<token-text xml:space="preserve">Current notification for Superuser: </token-text>
							<token-xpath expression="$current-node/@src-dn"/>
						</arg-string>
					</do-trace-message>
					<do-send-email-from-template notification-dn="~NotificationCollection~" template-dn="~AccountIdle1Template~">
						<arg-string name="to">
							<token-xpath expression="$current-node/instance/attr[@attr-name='mail']/value"/>
						</arg-string>
						<arg-string name="bcc">
							<token-global-variable name="DebugEmailAddress"/>
						</arg-string>
						<arg-string name="reply-to">
							<token-global-variable name="ReplyEmailAddress"/>
						</arg-string>
						<arg-string name="AccountName">
							<token-xpath expression="$current-node/AccountName"/>
						</arg-string>
						<arg-string name="Company">
							<token-xpath expression="$current-node/Company"/>
						</arg-string>
						<arg-string name="AccountDN">
							<token-xpath expression="$current-node/AccountDN"/>
						</arg-string>
						<arg-string name="AccountExpTime">
							<token-xpath expression="$current-node/LastLoginTime2"/>
						</arg-string>
						<arg-string name="NotificationText">
							<token-global-variable name="AccountIdle1Text"/>
						</arg-string>
					</do-send-email-from-template>
					<do-status level="success">
						<arg-string>
							<token-text xml:space="preserve">Notified </token-text>
							<token-xpath expression="$current-node/AccountName"/>
							<token-text xml:space="preserve"> (</token-text>
							<token-xpath expression="$current-node/EmailAddress"/>
							<token-text xml:space="preserve">) for an idle account. </token-text>
						</arg-string>
					</do-status>
					<do-generate-event id="~EventBase~04" level="log-info">
						<arg-string name="target">
							<token-xpath expression="$current-node/@src-dn"/>
						</arg-string>
						<arg-string name="target-type">
							<token-text xml:space="preserve">1</token-text>
						</arg-string>
						<arg-string name="text1">
							<token-text xml:space="preserve">Sent Email Notification to User.</token-text>
						</arg-string>
						<arg-string name="text2">
							<token-xpath expression="$current-node/EmailAddress"/>
						</arg-string>
						<arg-string name="text3">
							<token-text xml:space="preserve">Account Idle since </token-text>
							<token-xpath expression="$current-node/LastLoginTime2"/>
						</arg-string>
						<arg-string name="value">
							<token-xpath expression="$current-node/LastLoginTime"/>
						</arg-string>
					</do-generate-event>
				</arg-actions>
			</do-for-each>
			<do-for-each disabled="true">
				<arg-node-set>
					<token-xpath expression="AccountIdle1Superuser/instance[not(EmailAddress)]"/>
				</arg-node-set>
				<arg-actions>
					<do-trace-message color="white" level="3">
						<arg-string>
							<token-text xml:space="preserve">Current notification: </token-text>
							<token-xpath expression="$current-node/@src-dn"/>
						</arg-string>
					</do-trace-message>
					<do-status level="warning">
						<arg-string>
							<token-text xml:space="preserve">Could Not Notify </token-text>
							<token-xpath expression="$current-node/AccountName"/>
							<token-text xml:space="preserve"> (</token-text>
							<token-xpath expression="$current-node/AccountDN"/>
							<token-text xml:space="preserve">) that this account is idel since </token-text>
							<token-xpath expression="$current-node/AccountExpTime"/>
							<token-text xml:space="preserve">. No User Email Address found!</token-text>
						</arg-string>
					</do-status>
					<do-generate-event id="~EventBase~05" level="log-warning">
						<arg-string name="target">
							<token-xpath expression="$current-node/@src-dn"/>
						</arg-string>
						<arg-string name="target-type">
							<token-text xml:space="preserve">1</token-text>
						</arg-string>
						<arg-string name="text1">
							<token-text xml:space="preserve">Could Not Send Email Notification to User.</token-text>
						</arg-string>
						<arg-string name="text2">
							<token-text xml:space="preserve">No User Email Address Found!</token-text>
						</arg-string>
						<arg-string name="text3">
							<token-text xml:space="preserve">Account Idle since </token-text>
							<token-xpath expression="$current-node/LastLoginTime2"/>
						</arg-string>
						<arg-string name="value">
							<token-xpath expression="$current-node/PWExpTime"/>
						</arg-string>
					</do-generate-event>
				</arg-actions>
			</do-for-each>
		</actions>
	</rule>

There must be something wrong with the:
Code:
<arg-string name="to">
							<token-xpath expression="$current-node/instance/attr[@attr-name='mail']/value"/>
						</arg-string>
because it doesn't return a value. Here's part of the trace:

Code:
Action: do-send-email-from-template(notification-dn="Security\Default Notification Collection",template-dn="Security\Default Notification Collection\BCA - Account Idle BG",token-xpath("$current-node/instance/attr[@attr-name='mail']/value"),token-global-variable("DebugEmailAddress"),token-global-variable("ReplyEmailAddress"),token-xpath("$current-node/AccountName"),token-xpath("$current-node/Company"),token-xpath("$current-node/AccountDN"),token-xpath("$current-node/LastLoginTime2"),token-global-variable("AccountIdle1Text")).
[06/26/17 15:04:42.043]:BCA Idle Accounts Service PT:            to(token-xpath("$current-node/instance/attr[@attr-name='mail']/value"))
[06/26/17 15:04:42.043]:BCA Idle Accounts Service PT:              token-xpath("$current-node/instance/attr[@attr-name='mail']/value")
[06/26/17 15:04:42.044]:BCA Idle Accounts Service PT:                Token Value: "".
[06/26/17 15:04:42.045]:BCA Idle Accounts Service PT:              Arg Value: "".
Any suggestions how to get the correct email address with XPath? Any help is greatly appreciated.