Skip to content
Smart Templates Manual Website Manual for your AI

Own standards for the e-invoice

In short

A standard for the e-invoice consists of the official schema set (XSD, unchanged) and an own annotation file, which is itself a valid XSD. For every place in the document it states which entry goes there, what it is called, whether it is mandatory and which rules apply. This page describes its structure (format 1) so that developers and AI tools can write their own standards. It is uploaded in the designer under “Manage standards …” or with the action st_StandardHochladen.

Why an own standard

Smart Templates includes »XRechnung 3.0« (xrechnung-ubl) and »ZUGFeRD 2.5.2 (EXTENDED)« (zugferd-extended). An own standard is worthwhile if a recipient wants individual entries explained differently, demands additional checks or needs a different syntax. The easiest way: in the designer, choose “Save as file” for an included standard, adapt the file (own identifier, own texts, own rules) and upload it again.

Caution

Uploaded description files are not part of Smart Templates. Whoever uploads them is responsible for their content and its rights. Write names, explanations and messages yourself: texts from specifications, standards and Schematron rules are protected. Identifiers such as BT-1 or BR-CO-10 are references and may stay.

What a standard consists of

  • Schema set: the official XSD files, unchanged byte for byte. Included are ubl-2.1 (UBL 2.1 for XRechnung) and factur-x-1.09.2-extended (Factur-X/ZUGFeRD EXTENDED). An own standard uses one of them or brings its own set in a package.
  • Annotation file: an XSD with its own targetNamespace that only imports the schemas and describes them in xs:annotation blocks. It has exactly one root xs:schema; below it only xs:import and xs:annotation are allowed. Own declarations (xs:element, xs:complexType …) are rejected.
  • The core checks every element with the prefix st: against the format schema (action st_StandardLesen, part formatschema). Namespace: urn:smart-templates:e-rechnung:anmerkung:1.
XMLSkeleton of an annotation file
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           xmlns:st="urn:smart-templates:e-rechnung:anmerkung:1"
           xmlns:ubl="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2"
           xmlns:cn="urn:oasis:names:specification:ubl:schema:xsd:CreditNote-2"
           xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"
           xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"
           targetNamespace="urn:example:standard:my-xrechnung:1">
  <xs:import namespace="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2" schemaLocation="ubl-2.1/maindoc/UBL-Invoice-2.1.xsd"/>
  <xs:import namespace="urn:oasis:names:specification:ubl:schema:xsd:CreditNote-2" schemaLocation="ubl-2.1/maindoc/UBL-CreditNote-2.1.xsd"/>
  <xs:annotation> … one block per header, entry, list, group, code list, code name or check … </xs:annotation>
</xs:schema>
  • Prefixes: the prefixes in paths are those of the standard and are all declared on xs:schema. The XML is written with exactly these prefixes.
  • schemaLocation is never resolved: the core puts all files of the set together itself, without network and without file system.
  • A block is an xs:annotation directly below xs:schema with one xs:appinfo (containing exactly one carrier: st:standard, st:feld, st:liste, st:gruppe, st:codeliste, st:codename or st:pruefung) and next to it the texts as xs:documentation.
  • Texts: <xs:documentation source="name" xml:lang="de">…</xs:documentation>, source is name, erklaerung, grund, beispiel or meldung. Text only; whitespace is collapsed. A missing German mandatory text is an error; a missing English one is a note (the German one applies).

The header: st:standard

XMLHeader
<xs:annotation>
  <xs:appinfo>
    <st:standard kennung="my-xrechnung" fassung="1.0" formatVersion="1" syntax="UBL" schemasatz="ubl-2.1"
                 gueltigAb="2024-02-01" einbettbar="nein" downloadName="XRechnung_{BT-1}.xml" mime="application/xml">
      <st:wurzel element="ubl:Invoice" dokument="Invoice"/>
      <st:wurzel element="cn:CreditNote" dokument="CreditNote"/>
    </st:standard>
  </xs:appinfo>
  <xs:documentation source="name" xml:lang="de">Meine XRechnung</xs:documentation>
  <xs:documentation source="name" xml:lang="en">My XRechnung</xs:documentation>
</xs:annotation>
AttributeMandatoryMeaning
kennungyesFamily, the same across versions: lower-case letters, digits, -, at most 60 characters. The identifiers of the included standards are locked.
fassungyesLetters, digits, . and -, at most 40 characters.
formatVersionyesVersion of this format, today 1. A higher one requires a newer version of Smart Templates.
syntaxyesdisplay only, such as UBL or CII.
schemasatzyesan included set (ubl-2.1, factur-x-1.09.2-extended) or eigen (schema files in the package).
gueltigAb, gueltigBis–date YYYY-MM-DD. Without a version in the template, the newest valid one applies.
nachfolgerVon–versions of the same identifier that this one replaces (separated by spaces).
einbettbaryesja or nein: whether »PDF with embedded e-invoice« is offered. ja requires st:einbettung.
downloadNameyesfile name; placeholders {BT-x} only with header entries; without /, \, :.
mimeyesapplication/xml, text/xml or an application/…+xml.
  • st:wurzel (at least one): element (the root element) and dokument (name of the document form, unique). Several roots need an entry that chooses the form (see »Code lists and document form«).
  • st:einbettung (at most one): dateiname, beziehung (Data, Source, Alternative, Supplement, Unspecified), pdfa (such as 3B), profil, version (default 1.0), dokumentArt (default INVOICE). From it the attachment and the metadata of the PDF/A-3 are built.

Entries: st:feld

XMLEntry
<xs:annotation><xs:appinfo>
  <st:feld id="BT-84" abschnitt="zahlung" liste="BG-17" typ="kennung" pflicht="wenn"
           wenn="[BT-81] == '30' || [BT-81] == '58'" bereinigen="ohneLeerzeichen grossbuchstaben">
    <st:pfad>/ubl:Invoice/cac:PaymentMeans/cac:PayeeFinancialAccount/cbc:ID</st:pfad>
    <st:pfad>/cn:CreditNote/cac:PaymentMeans/cac:PayeeFinancialAccount/cbc:ID</st:pfad>
  </st:feld></xs:appinfo>
  <xs:documentation source="name" xml:lang="de">IBAN</xs:documentation>
  <xs:documentation source="erklaerung" xml:lang="de">Ihre Kontonummer, auf die der Kunde zahlen soll.</xs:documentation>
  <xs:documentation source="grund" xml:lang="de">bei Zahlung per Überweisung</xs:documentation>
</xs:annotation>
AttributeMandatoryMeaning
idyesIdentifier starting with a letter, at most 40 characters: the BT-… of EN 16931 (accompanying entries BT-34-1), otherwise own ones. Entries, lists and groups share the identifiers.
abschnittyesrechnung, verkaeufer, kunde, lieferung, zahlung, positionen, nachlaesse, steuern or weiteres: where the entry appears in the assignment window.
liste, gruppe–the list or group it belongs to. Without liste it is a header entry.
typyestext, kennung, code, datum, betrag, preis, menge, prozent or janein.
codeliste, erkennenwith codethe code list (only and always with code); erkennen="ja": names and synonyms become the code.
pflichtyesja, nein or wenn (then with wenn = an expression of the check language and a text grund).
zuordnung–frei (default), vorgabe (pre-filled with wert, changeable), fest (always wert, not shown in the window) or laufendeNummer (lists only: the window offers »running number«).
wertwith vorgabe, festthe value.
haeufig–ja: shown in the window straight away.
max, muster–maximum length; regular expression for the whole value (time limit 100 ms). Both apply to the cleaned value.
bereinigen–ohneLeerzeichen, grossbuchstaben (separated by spaces).
nachkommastellen–how many decimal places the standard allows (0 to 10) or frei. Numbers only. Without it: betrag 2, preis, menge, prozent without a limit. Values are rounded commercially to this many places before checking; frei does not round.
pflichtwert–text for a place only the schema requires (the standard has no value for it), such as NA. An assigned value comes first; the mandatory value never counts as content. Only with text, kennung, code.
begleitwert–ja: the value does not make its container appear; it is in the XML only if the container appears for another reason. Not together with pflicht="ja".

Type against schema: betrag, preis, menge and prozent only on numeric types (xs:decimal and derived), datum on xs:date or on text with a type rule format (CII), janein on xs:boolean, text, kennung and code on text types. Written invariantly with a dot, without thousands separators; amounts and prices with at least 2 places, dates as yyyy-MM-dd or by type rule, truth values true/false. Identifiers and codes are trimmed at both ends, texts only by whitespace that is not a line break.

Several paths: one path per document form. Several paths of the same form are a conditional path: all but the last carry wenn, the first that matches applies. Further attributes on st:pfad: wurzel, wenn, jeEintrag="alle" and format (see »Path language«).

Path language

A small subset of XPath 1.0:

TEXTPath language
Path      := "/" Step ( "/" Step )*                    at most 64 steps, 2,000 characters
Step      := Prefix ":" Name Predicate?  |  "@" Name   attribute only as the last step, without prefix
Predicate := "[" Number "]"                             number, from 1
           | "[" Rel "='" Value "']"                    feature equal
           | "[not(" Rel ")]"                           feature missing
           | "[not(" Rel "='" Value "')]"               feature not equal
Rel       := ( Prefix ":" Name "/" )* ( Prefix ":" Name | "@" Name )
  • At most one predicate per step; values in single quotes, without ' inside.
  • Number cac:TaxTotal[2]: the second occurrence. Numbers without gaps: whoever names [2] needs an entry in [1].
  • Feature equal cac:PartyTaxScheme[cac:TaxScheme/cbc:ID='VAT']: the occurrence whose child has this value. The feature is also a fixed value and is written as soon as the occurrence appears.
  • Feature missing cac:AdditionalDocumentReference[not(cbc:DocumentTypeCode)]: nothing below this occurrence may write into the feature path.
  • Feature not equal cac:PartyIdentification[not(cbc:ID/@schemeID='SEPA')]: a value with the excluded value is an error when writing.
  • Two occurrences of the same element below the same parent occurrence must be distinguishable: different numbers, different values of the same feature, »equal« against »missing« or »equal« against »not equal«. Anything else is an error.
  • A step without a predicate on a repeatable element that is not a list means one shared occurrence (like [1]): name, phone and e-mail of a contact end up in one contact.
  • Conditional path: several st:pfad with wenn, if the element depends on the value. On a list the condition decides per entry.
  • Header entry, element in a list: a header path through a list needs [n] (only into the n-th occurrence) or jeEintrag="alle" (into every one). Such a list appears at least once, even without an entry.
  • Composition format="[#{BT-21}#]{BT-22}": {identifier} is a value, [ … ] is dropped as soon as an entry inside is empty; {{, }}, [[, ]] write the characters. The composition names the entry that carries it.

Lists and groups

XMLList and group
<st:liste id="BG-25" abschnitt="positionen" min="1" quelle="regel eintraege">
  <st:pfad>/ubl:Invoice/cac:InvoiceLine</st:pfad>
  <st:pfad>/cn:CreditNote/cac:CreditNoteLine</st:pfad>
</st:liste>
<st:gruppe id="BG-6" abschnitt="verkaeufer">
  <st:pfad>/ubl:Invoice/cac:AccountingSupplierParty/cac:Party/cac:Contact</st:pfad>
</st:gruppe>
  • List: the path of a repeatable element; one occurrence per entry. Predicates on the list element are allowed (…/cac:AllowanceCharge[cbc:ChargeIndicator='false']). Attributes: liste (the parent list), gruppe, min and max (only where the standard is stricter than the schema), quelle (regel, eintraege or both), wert="selbst" (the list element itself is the value, with exactly one entry) and haeufig. A list needs a path for every document form in which its entries occur.
  • Line items: the top line item list carries abschnitt="positionen", its line identifier zuordnung="laufendeNummer".
  • Group without repetition: a sub-heading in the window. filled([BG-x]) is true as soon as an entry of the group has a value. A group can lie inside another one (gruppe="BG-11"); filled then also sees the sub-groups.

Fixed values, attributes, type rules, locks

ElementExampleMeaning
st:fest<st:fest pfad="…/cac:TaxScheme/cbc:ID" wert="VAT"/>fixed text or attribute value. Does not count as content: a container with only fixed values does not appear.
st:attribut<st:attribut pfad="…/cbc:TaxAmount/@currencyID" quelle="BT-6"/>an attribute from an entry; does not count as content.
st:typregel<st:typregel xsdTyp="udt:AmountType"><st:attribut pfad="@currencyID" quelle="BT-5"/></st:typregel>applies at every place of this type (or a derived one); children with a relative path; schreibweise (yyyy-MM-dd, yyyyMMdd) for dates.
st:gesperrt<st:gesperrt element="cbc:EmbeddedDocumentBinaryObject" kennungen="BT-125" grund="…"/>a locked place via exactly one of pfad, xsdTyp, element. An entry on it is an error.

Precedence on an attribute: entry before fixed value or feature, before st:attribut on the path, before st:attribut from a type rule, before a fixed value from a type rule. Two different sources of the same kind at the same place are an error.

Code lists and document form

XMLCode list
<st:codeliste id="EINHEIT" quelle="UN/ECE Rec 20/21">
  <st:code wert="H87" haeufig="ja" synonyme="pcs;piece"/>
  <st:code wert="C62"/>
</st:codeliste>
  • The codes are complete in the list. Common codes get names through an own block st:codename (liste, wert) with texts; rare ones appear as code. namen="cldr-49" on the code list takes country names from the included list (Unicode CLDR 49).
  • Recognition: without regard to case against code, names and synonyme (separated by ;). Two different hits give no result; nothing is guessed. The conversion of the template applies in addition.
  • Document form: with several st:wurzel there is exactly one header entry of type code whose code list carries dokument="…" on every code (XRechnung: BT-3, 380 becomes Invoice, 381 CreditNote). Empty or unknown is an error.

Mandatory, »mandatory if …« and checks

Mandatory comes from two sources: the schema (a mandatory element below a written container needs a value) and the annotation (pflicht, st:pruefung).

XMLCheck
<st:pruefung id="BR-CO-17" art="rechnung" stufe="fehler" je="BG-23" felder="BG-23/BT-117 BG-23/BT-116 BG-23/BT-119"
             bedingung="abs([BT-117] - round([BT-116] * [BT-119] / 100, 2)) &lt; 1"/>
<!-- next to it: xs:documentation source="meldung" xml:lang="de" with the message in plain language -->
AttributeMeaning
ididentifier of the rule (reference to the standard) or an own ST-….
artpflicht, rechnung (arithmetic check), gruppierung, code, muster or sonst.
stufefehler (no document) or hinweis (document is created). An arithmetic check is always fehler, with the tolerance of the standard in the expression.
verbindlichonly and mandatory with gruppierung: the identifier of the arithmetic check (art="rechnung", same je) this grouping check belongs to.
jethe list whose entries are checked one by one; the message names the entry.
felderthe entries involved (BT-x or List/BT-x).
bedingungmust be true, otherwise the message applies (text meldung, German mandatory).

Check language

TEXTCheck language
Expression := Or
Or         := And ( "||" And )*            And  := Equal ( "&&" Equal )*
Equal      := Comp ( ("=="|"!=") Comp )*    Comp := Sum ( ("<"|"<="|">"|">=") Sum )*
Sum        := Prod ( ("+"|"-") Prod )*     Prod := Unary ( ("*"|"/") Unary )*
Unary      := ("!"|"-") Unary | Primary
Primary    := "(" Expression ")" | "[" Id ("/" Id)* "]" | "'" Text "'" | Number | true | false | Function "(" Arguments ")"
  • [BT-81] is the value of an entry. An entry of a list only inside an entry of its list (je, any, all or a reference of the same list), otherwise [BG-25/BT-131] for all values. [BG-15] stands for a group or list only in filled, count, any and all.
  • Text in single quotes ('' is a quote), numbers with a dot, true and false.
  • Functions: filled(x), sum([L/F]) and sum([L/F], b) (only entries in which b is true), count([L]), count([L/F]) and count([L], b), any([L], b), all([L], b), round(x, n) (n from 0 to 10, commercially), abs(x), matches(x, 'regex') (time limit 100 ms, empty is false), iban(x) (check digit), aussen(x) (only in a condition of sum, count, any, all: evaluates x in the entry outside the innermost iteration).
  • Calculation uses decimal numbers. Empty counts as 0 when calculating; compared with a number as 0, with text as empty text. true and false only with == and !=; empty is not false. A condition is met only when true.
  • Checked when loading: unknown identifiers, entries of a list outside their entries, text in calculations, lists in comparisons, groups outside filled, a condition that does not give a truth value.
  • Tolerances are in the expression itself, such as abs(…) < 1 or <= 0.02.
  • Regular expressions are those of .NET, the standards write XPath: end of text as (?![\s\S]) instead of $, whitespace as [ \t\r\n] instead of \s, »any character of the line« as [^\r\n]. The value is checked before writing; a line break can be CR, CRLF or LF.

Order on a document: first values of unknown identifiers, of the wrong level or without a place in the document form; then per level (header, every entry) format, pflicht, wenn, code, max, muster; then min and max of the lists; finally every st:pruefung. Empty is: missing, null, empty text or only whitespace; 0 and false are values.

What happens when generating

  • The XML is built from the root in the order of the compiled schema. A container appears only with assigned content or because the schema requires it; a mandatory text without a value is then an error. With a choice in the schema the branch with values applies (two filled ones are an error).
  • Data type and facets (length, pattern, enumeration) are checked before writing; more occurrences than allowed are an error. Finally every non-empty value is compared with what was written: nothing gets lost silently.
  • Written as UTF-8 without BOM, with a declaration and all namespaces at the root. Afterwards the core checks the finished XML against the schema set; every warning outside extension areas is an error.

Uploading: file or package

  • File (.xsd): an annotation file on an included schema set. Smart Templates packs it for storage.
  • Package (.zip): exactly one annotation file (the only .xsd with the st: namespace) and, with schemasatz="eigen", the schema files. Only .xsd; absolute paths, drives, .., empty path parts and duplicate names are rejected. With an included schema set the package contains only the annotation file. In own schema sets, patterns with nested repetitions are rejected.
  • The core checks completely before it stores anything. If identifier and version already exist, it overwrites only with »replace« (designer: question; action: Ersetzen = ja). A deactivated row does not count, just as in the list and when printing: uploading a deactivated standard again creates a new, active row; the deactivated one stays as it is. In Dynamics, own standards are stored in the table st_erechnungstandard; uploading and deleting requires the security role »Smart Templates Designer«.
LimitValue
Package, packed768 KiB
unpacked or annotation file10 MB
Files in the package100
Entries5,000
Path64 steps, 2,000 characters
Expression4,000 characters, nesting 64
Nesting of every XSD128 levels
Regular expressionstime limit 100 ms
DTD, external referencesforbidden

Findings when loading carry a code and a location (file, line, column), such as xml.wohlgeformt, format.schema, text.fehlt, id.doppelt, ausdruck.syntax, pfad.schritt, pfad.doppeltreffer, liste.eltern, pflicht.ohneAngabe, standard.gesperrt, paket.zip or grenze.angaben. Notes such as text.englisch do not prevent storing.

The overview

From the standard, the core builds an overview for the assignment window, the AI assistant and the AI package: sections, entries (identifier, name, explanation, reason, mandatory from standard and schema, type, list, group, code list), lists (source, min, mandatory from the schema), groups, code lists (common codes) and checks. It is a view, never stored, without paths and without XML. The action st_StandardLesen returns it:

TeilContent
empty or uebersichtthe whole overview, code lists only with common codes
pflichtonly mandatory entries (standard or schema)
abschnitt:<id>one section
codeliste:<id>one code list with all codes
vorschlaegethe suggestions for the Dynamics invoice (with an identifier, cut to the standard)
anmerkungthe annotation file as text
schema:<datei>one file of the schema set
formatschemathe format schema of the annotation files
formatthis description as Markdown

Without Kennung the action returns the list of standards (included and own ones); Sprache = en returns the English texts.

Good to know

How to view standards in the designer, save them as a file, upload them and delete them is described in E-invoice: Own standards. How a template assigns the entries of a standard (the key eRechnung) is described under Template format: E-invoice, and the actions under Actions and APIs: E-invoice.