<?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" xmlns:ns2="http://examplotron.org/0/" xmlns:ns3="http://http://examplotron.org/otherns/" version="1.0" ns1:dummy="" ns2:dummy="" ns3: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(ns3:bar)&gt;0 and 1=1 and  1=1]"/>
   </x:template>
   <x:template priority="1" match="/foo[count(ns3:bar)&gt;0 and 1=1 and  1=1]">
      <x:apply-templates select="*|@*"/>
   </x:template>
   <x:template match="/foo/ns3:bar">
      <error type="Element content mismatch" name="/foo/ns3:bar" expected="[@true and  1=1]"/>
   </x:template>
   <x:template priority="1" match="/foo/ns3:bar[@true and  1=1]">
      <x:apply-templates select="*|@*"/>
   </x:template>
   <x:template priority="1" match="/foo/ns3:bar/@true"/>
   <x:template match="/foo/ns3:bar">
      <error type="Element content mismatch" name="/foo/ns3:bar" expected="[ 1=1]"/>
   </x:template>
   <x:template priority="1" match="/foo/ns3:bar[ 1=1]">
      <x:apply-templates select="*|@*"/>
   </x:template>
</x:stylesheet>