应用并不存在的XSLT标签 [英] Apply XSLT tags that aren't there

查看:132
本文介绍了应用并不存在的XSLT标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用XSLT将XML文档转换成乳胶。我有两个标记<林> < GRA> 其中,粗略地讲,对应于一个段落和一个文字大小选择,分别为。然而,在情况下<林> 是从内部运行< BLOK RYK =lyrik> 标签,我想<林> 将同样地应用于<林RYK =郎>< GRA海峡= - 1> 。我知道我可以只复制了后者的定义,但有几个原因,所提到的解决方案是为preferred。我感到非常幸运,并决定尝试以下code:

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="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>

这没有工作,因为&LT;林RYK =郎&GT;&LT; GRA海峡= - 1&GT; code是完全忽略。这也许有点乐观地希望,你可以只是简单地写出来的code这个样子。那么是什么的的我都做了些什么?这里是一块示例XML code的将其应用到:​​

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

我得到的输出仅仅是没有标签一样。

The output I get is simply the same without the tags.

\documentclass{memoir}

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

我要的是以下内容:

What I want is the following:

{\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。如果有人使用&LT; XSL:复制&GT; 的解决方案,请的给我解释一下该标签确实的。我读过无数的教程和示例,仍然没有真正得到它。

P.S. If someone uses <xsl:copy> in the solution, please explain to me what that tag really does. I've read countless tutorials and examples and still don't really get it.

推荐答案

我想你想创建一个变量

&LT;的xsl:模板匹配=BLOK [@ RYK ='lyrik'] /林优先=7&GT;
&LT; XSL:变量名=L1&GT;
 &LT;林RYK =郎&GT;&LT; GRA海峡= - 1&GT; &LT; XSL:复制的选择=节点()/&GT; &LT; / GRA&GT;&LT; / LIN&GT;
&LT; / XSL:变量&GT;
&LT; XSL:申请模板选择=$ L1 /节点()/&GT;
&LT; / XSL:模板&GT;

这篇关于应用并不存在的XSLT标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆