2013-10-15 29 views
2

我完全是XSLT的新手(Iam使用氧氣,XSLT 2.0) 我試圖在網上找到解決方案,但無法找到答案。XSLT 2.0適用於不同情況的一個元素(@模式不起作用)

我有以下情況: 我有一個XML(TEI)在段落中有不同的'term'元素。我想用條款做不同的事情,但用@mode它不起作用。 1.我想給鏈接條款 2.當'lb'在'term'內時我想匹配元素'lb /' - >元素'br /'(<term> tex <lb /> t </term>) 3.我想讓' del'在我的HTML中,當它在'term'內時消失 4.如果在'term'中是一個分隔符' - '我想插入到我的html'文本不會生成no義):

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

我想要的「德爾」的內容消失。

+0

請發佈您希望爲您發佈的輸入樣本創建的結果。 ' t ...'會發生什麼情況',你是否想要刪除'del'幷包含它的內容,或者是否要刪除該元素但保留其內容? –

+0

感謝您的回覆!編輯我的帖子 –

回答

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/><lb/>是內<term>

這就是:

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

我要讓<del> dissappear在我的HTML時,其內<term>

這是

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

而且,V紅黴素可能你想要這個,太:

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

如果內<term>是一個分隔符"-"我想在我的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>
  • 整個字符串內容應該(即,必須)構建URL時使用encode-for-uri()功能。
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> 
+0

謝謝你們兩位!我終於明白我的錯誤是什麼!我正在尋找一個星期的解決方案,所以你救了我的一天!謝謝!! –

+0

+1似乎我們有同樣的想法。 :) – Tomalak

相關問題