2

我对 XSLT 完全陌生(我正在使用氧气,XSLT 2.0)我试图在网上和我的书中找到解决方案,但无法弄清楚。

我有以下情况:我有一个 XML (TEI),它在段落中有不同的“术语”元素。我想用这些术语做不同的事情,但使用@mode 它不起作用。1. 我想给术语一个链接 2. 我想匹配元素 'lb/' -> 元素 'br/' 当 'lb' 在 'term' ( <term> tex <lb /> t </term>) 内 3. 我想让 'del' 消失我的 html 在 'term' 内时 4. 如果在 'term' 内是分隔符“-” 我想在我的 html 中插入 'br/'

我的 XML 的摘录(文本没有意义):

<p>und <term>toxische <lb/>
    Quote</term> dabei eine Rolle. – text<term><del>t</del><add rend="overtyped">t</add><del>t</del><add type="overtyped">l</add></term>leicht teilen Sie mir einmal <lb/>
    freundlichst Ihre Ansicht mit.</p> 

4.我用这个:

<xsl:template match="tei:term">

<xsl:variable name="linktext" select="text()"/>
<a href="https://de.wikipedia.org/wiki/{$linktext}" target="_blank"> 
    <xsl:for-each select="tokenize(.,'-')">
        <xsl:sequence select="."/>
        <xsl:if test="not(position() eq last())">-<br /></xsl:if>
    </xsl:for-each> 

  </a>

我尝试在其他情况下使用@modes,但它没有用。有谁知道我该如何编码?

提前致谢!!

我想要的结果是以下html代码:

<p> und <a href="href="https://de.wikipedia.org/wiki/toxischeQuote">toxische<br/>
Quote</a> dabei eine Rolle. - text<a      href="href="https://de.wikipedia.org/wiki/texttl">
texttl</a> leicht teilen Sie mir einmal <br/> freundlichst Ihre Ansicht mit. </p>

我希望“del”的内容消失。

4

2 回答 2

1
<xsl:template match="tei:term">
  <a href="https://de.wikipedia.org/wiki/{.}" target="_blank">
    <xsl:apply-templates/>
  </a>
</xsl:template>

<xsl:template match="tei:term/tei:lb">
  <br/>
</xsl:template>

<xsl:template match="tei:term/tei:del"/>

<xsl:template match="tei:term//text()">
<xsl:for-each select="tokenize(.,'-')">
        <xsl:sequence select="."/>
        <xsl:if test="not(position() eq last())">-<br /></xsl:if>
    </xsl:for-each>
</xsl:template>
于 2013-10-15T13:55:52.697 回答
1

我想给条款一个链接

那是:

<xsl:template match="tei:term">
  <xsl:variable name="linktext" select="
    normalize-space(string-join(.//text()[not(parent::del)], ''))
  " />  <!-- ... or something like that -->

  <a href="http://de.wikipedia.org/w/index.php?search={encode-for-uri($linktext)}" target="_blank"> 
    <xsl:apply-templates select="node()" />
  </a>
</xsl:template>

我想匹配元素<lb/>-> <br/>when <lb/>is within<term>

那是:

<xsl:template match="tei:term/tei:lb">
  <br />
</xsl:template>

我想<del>在我的 HTML 中消失<term>

那是

<xsl:template match="tei:term/tei:del" />

而且,你很可能也想要这个:

<xsl:template match="tei:term/tei:add">
  <xsl:value-of select="." />
</xsl:template>

如果<term>inside 是一个分隔符"-",我想在我的 html 中插入<br/>

那是

<xsl:template match="tei:term/text()">
  <xsl:for-each select="tokenize(., '-')">
    <xsl:sequence select="." />
    <xsl:if test="not(position() = last())">-<br /></xsl:if>
  </xsl:for-each> 
</xsl:template>

注意

  • 这种方法<term>按其出现顺序处理 的子节点<xsl:apply-templates>。然后很容易通过特定的模板来实现你的规则。
  • 您只想标记单个文本节点,而不是整个字符串内容<term>
  • 您应该(即,必须)encode-for-uri()在构建 URL 时使用该函数。
于 2013-10-15T13:54:45.280 回答