Apply XSLT tags that aren't there

Tuesday, July 8, 2014

I am trying to convert an XML document into LaTeX using XSLT. I have two tags <lin> and <gra> which, roughly speaking, correspond to a paragraph and a choice of text size, respectively. However, in the case where <lin> is run from within a <blok ryk="lyrik"> tag, I want <lin> to be applied identically to <lin ryk="lang"><gra str="-1">. I know I could just copy the definition of the latter, but for several reasons, the mentioned solution is to be preferred. I felt very lucky and decided to try the following code:

<xsl:stylesheet version="2.0" xmlns:xsl="">
<xsl:output method="text" omit-xml-declaration="yes" encoding="UTF-8"/>
<xsl:template match="/">




<xsl:template match="lin[@ryk='lang']"><!--
-->{\parindent=3em <xsl:apply-templates/><xsl:text>}

<xsl:template match="gra[@str='-1']">{\small <xsl:apply-templates/>}</xsl:template>

<xsl:template match="blok[@ryk='lyrik']/lin" priority="7">
<lin ryk="lang"><gra str="-1">

This did not work, since the <lin ryk="lang"><gra str="-1"> code is completely ignored. It was perhaps a bit optimistic to hope that you could just simply write out the code this way. But then what should I have done? Here is a piece of example XML code to apply it to:

<?xml version="1.0" encoding="UTF-8"?>
<blok ryk="lyrik">
<lin>Attributes are red.</lin>
<lin>Tags are blue.</lin>
<lin>Text is black.</lin>
<lin>Please help my code compute.</lin>