应用不存在的XSLT标记

时间:2014-07-08 19:31:32

标签: xslt attributes latex

我正在尝试使用XSLT将XML文档转换为LaTeX。我有两个标签<lin><gra>,粗略地说,分别对应于段落和文本大小的选择。但是,如果在<lin>代码中运行<blok ryk="lyrik">,我希望<lin>同样适用于<lin ryk="lang"><gra str="-1">。我知道我可以复制后者的定义,但由于几个原因,所提出的解决方案是首选。我感到非常幸运,并决定尝试以下代码:

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" omit-xml-declaration="yes" encoding="UTF-8"/>
<xsl:template match="/">

\documentclass{memoir}

\begin{document}
<xsl:apply-templates/>
\end{document}

</xsl:template>

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

<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">
<xsl:apply-templates/>
</gra></lin>
</xsl:template>

这不起作用,因为完全忽略了<lin ryk="lang"><gra str="-1">代码。希望你可以简单地用这种方式编写代码也许有点乐观。但那么应该我做了什么?下面是一段将其应用于的示例XML代码:

<?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>
</blok>

我得到的输出与标签完全相同。

\documentclass{memoir}

\begin{document}
Attributes are red.
Tags are blue.
Text is black.
Please help my code compute.
\end{document}

我想要的是以下内容:

{\small\parindent=3em Attributes are red.}
{\small\parindent=3em  Tags are blue.}
{\small\parindent=3em  Text is black.}
{\small\parindent=3em  Please help my code compute.}}

P.S。如果有人在解决方案中使用<xsl:copy>,请向我解释该标记的真正含义。我已经阅读了无数的教程和示例,但仍然没有真正得到它。

1 个答案:

答案 0 :(得分:2)

我认为你想创建一个变量

<xsl:template match="blok[@ryk='lyrik']/lin" priority="7"> <xsl:variable name="l1"> <lin ryk="lang"><gra str="-1"> <xsl:copy-of select="node()"/> </gra></lin> </xsl:variable> <xsl:apply-templates select="$l1/node()"/> </xsl:template>

相关问题