<?xml version="1.0" encoding="UTF-8"?>
<x:stylesheet xmlns:x="http://www.w3.org/1999/XSL/Transform" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:eg="http://examplotron.org/0/" xmlns:saxon="http://icl.com/saxon" xmlns:ns1="http://www.w3.org/XML/1998/namespace" version="1.0" ns1:dummy="">
   <x:template match="*">
      <error type="Unexpected element">
         <x:attribute name="path">
            <x:call-template name="getPath"/>
         </x:attribute>
      </error>
   </x:template>
   <x:template match="@*">
      <error type="Unexpected attribute">
         <x:attribute name="path">
            <x:call-template name="getAttPath"/>
         </x:attribute>
      </error>
   </x:template>
   <x:template name="getPath">
      <x:for-each select="parent::*">
         <x:call-template name="getPath"/>
      </x:for-each>
      <x:variable name="name" select="name()"/>
      <x:value-of select="concat('/', $name, '[', count(preceding-sibling::*[name()=$name])+1, ']')"/>
   </x:template>
   <x:template name="getAttPath">
      <x:for-each select="parent::*">
         <x:call-template name="getPath"/>
      </x:for-each>
      <x:variable name="name" select="name()"/>
      <x:value-of select="concat('/@', $name)"/>
   </x:template>
   <x:template priority="1" match="/">
      <x:apply-templates select="*|@*"/>
   </x:template>
   <x:template match="/foo">
      <error type="Element content mismatch" name="/foo" expected="[count(bar)=2 and  1=1]"/>
   </x:template>
   <x:template priority="1" match="/foo[count(bar)=2 and  1=1]">
      <x:apply-templates select="*|@*"/>
   </x:template>
   <x:template match="/foo/bar">
      <error type="Element content mismatch" name="/foo/bar" expected="[ 1=1]"/>
   </x:template>
   <x:template priority="1" match="/foo/bar[ 1=1]">
      <x:apply-templates select="*|@*"/>
   </x:template>
   <x:template match="/foo/bar">
      <error type="Element content mismatch" name="/foo/bar" expected="[ 1=1]"/>
   </x:template>
   <x:template priority="1" match="/foo/bar[ 1=1]">
      <x:apply-templates select="*|@*"/>
   </x:template>
</x:stylesheet>