Le 02/05/2015 23:42, Peter Flynn a écrit :
> I have defined a new XSLT2 dialect of XML for the listings package which
> includes some extra keywords beyond XSLT, but I can't get it to
> recognise this: I get the error message
>
>> ! Package Listings Error: Couldn't load requested language.
>> [...]
>
> Here is the MWE (extra keywords cut):
>
> ---------------------------------8<----------------------------
> [...]
> \begin{lstlisting}[language=XSLT2]
> ---------------------------------8<----------------------------
>
> What am I doing wrong?
>
> I am aware that I can use [language={[XSLT2]XML}],
Not only you can: you *must* use [language={[XSLT2]XML}]. XSLT2 isn't
a language and the error message is clear enough about that.
> but if I use the
> existing XSLT language I don't have to do {[XSLT]XML}
Because XSLT is a language, not a dialect of XML (from listings point
of vue of course). In lstlang1.sty, XSLT is defined like that:
\lst@definelanguage{XSLT}[]{XML}
You define the XSLT2 like that:
\lstdefinelanguage[XSLT2]{XML}
That's not the same! There is a '[]' very important in XSLT definition :-)
>...how do I
> implement it so that it works in the same way? I have tried using
> \lstset{defaultdialect=[XSLT2]XML} but it has no effect.
You have to insert the empty optional argument in order to specify a
base language for your new language:
\documentclass{article}
\usepackage{listings}
\lstdefinelanguage{XSLT2}[]{XML}%
{morekeywords={xsl:for-each-group},%
alsodigit={-},%
}%
\lstloadlanguages{XSLT2}
\begin{document}
This is a test
\begin{lstlisting}[language=XSLT2]
<xsl:for-each-group select="db:biblioentry">
...
</xsl:for-each-group>
\end{lstlisting}
\end{document}
Jean-Côme Charpentier