2015-02-09 61 views
0

我有一個正是如此格式的XML塊:應用XSLT記號化功能的應用模板結果

<line n="2"> 
     <orig>of right hool herte <ex>&amp;</ex> in our<ex>e</ex><note place="bottom" anchored="true" xml:id="explanatory">Although 「r」 on the painted panels of the chapel is consistently written with an otiose mark when it concludes a word, the mark here is rendered more heavily and with a dot indicating suspension above the r. This rendering as 「our<ex>e</ex>」 is a linguistic outlier for the area based on the electronic <emph rend="italic">Linguistic Atlas of Late Medieval English</emph>’s linguistic profiles for 「oure,」 「our,」 and 「our<ex>e</ex>.」 See eLALME's <ref target="http://archive.ling.ed.ac.uk/ihd/elalme_scripts/mapping/user-defined_maps.html">User Defined Maps</ref> for more information. Unfortunately the current online version (as of 12 July 2014) does not allow direct linking between static dotmaps and linguistic profiles.</note> best entent</orig> 
</line> 

我需要能夠減少它只是明文:「右HOOL herte &的以最佳範圍「,然後在空間上標記以獲得逗號或標籤分隔值的列表。我有明文通過下面的XSLT完成了位:

<xsl:template match="tei:line" > 
     <xsl:apply-templates /> 
</xsl:template> 

<xsl:template match="orig"> 
    <xsl:apply-templates/> 
</xsl:template> 

<xsl:template match="ex"> 
    <xsl:apply-templates/> 
</xsl:template> 

<xsl:template match="note"/> 

但是,我不能得到令牌化功能與應用模板的工作。如果我嘗試使用value-of,那麼標籤下面的標籤將不再正常工作。有什麼辦法可以在xml上運行apply-templates,然後在單個xslt中標記每個元素?謝謝!

+0

我沒有看到你在代碼示例中的任何地方調用'tokenize'。 – PhillyNJ 2015-02-09 22:02:26

+0

這個練習的預期結果是什麼? - 注意:您的前三個模板似乎是多餘的,因爲內置的模板規則可以做到這一點。 – 2015-02-09 22:16:43

+0

我不會調用標記大小,因爲它根本不適用於應用程序模板。如果我使用value-of來調用它,例如select =「tokenize(。,'')」,那麼抑制音符不再起作用,或者它將標記爲「oure」中已包裝在標記中的e 。 – medievalmatt 2015-02-10 23:20:03

回答

0

我需要能夠減少它只是明文:在歐勒最好的「右HOOL herte &的entent「,然後在空格上標記以獲得以逗號或標記分隔值的列表的 列表。

不確定「tag-separated values」是什麼意思。鑑於以下測試輸入

XML

<root> 
    <line n="2"> 
      <orig>of right hool herte <ex>&amp;</ex> in our<ex>e</ex><note place="bottom" anchored="true" xml:id="explanatory">Although 「r」 on the painted panels of the chapel is consistently written with an otiose mark when it concludes a word, the mark here is rendered more heavily and with a dot indicating suspension above the r. This rendering as 「our<ex>e</ex>」 is a linguistic outlier for the area based on the electronic <emph rend="italic">Linguistic Atlas of Late Medieval English</emph>’s linguistic profiles for 「oure,」 「our,」 and 「our<ex>e</ex>.」 See eLALME's <ref target="http://archive.ling.ed.ac.uk/ihd/elalme_scripts/mapping/user-defined_maps.html">User Defined Maps</ref> for more information. Unfortunately the current online version (as of 12 July 2014) does not allow direct linking between static dotmaps and linguistic profiles.</note> best entent</orig> 
    </line> 
</root> 

以下樣式:

XSLT 2.0

<xsl:stylesheet version="2.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> 

<xsl:template match="/root"> 
    <xsl:copy> 
     <xsl:apply-templates select="line"/> 
    </xsl:copy> 
</xsl:template> 

<xsl:template match="line"> 
    <xsl:variable name="line-text"> 
     <xsl:apply-templates/> 
    </xsl:variable> 
    <xsl:copy> 
     <xsl:copy-of select="@n"/> 
     <xsl:value-of select="tokenize(normalize-space($line-text), ' ')" separator=", "/> 
    </xsl:copy> 
</xsl:template> 

<xsl:template match="note"/> 

</xsl:stylesheet> 

將返回:

<?xml version="1.0" encoding="UTF-8"?> 
<root> 
    <line n="2">of, right, hool, herte, &amp;, in, oure, best, entent</line> 
</root> 
+0

只是好奇,爲什麼你回答這個問題時,OP甚至沒有顯示嘗試?再一次,好奇。 – PhillyNJ 2015-02-09 23:21:19

+0

@PhilVallone首先,因爲它很有趣。一旦我有了解決方案,我就無處可去,只是在這裏。 OP *做了一些嘗試。當有人被困在不知道要轉向的方向時,我不明白在要求他們爲努力而努力時有什麼意義。最後,我不是OP的母親,我不是來檢查他們的家庭作業或他們的指甲(如果你想......我可以寫更多的關於這個的東西)。 – 2015-02-09 23:37:33

+0

夠公平!沒有必要寫更多。 – PhillyNJ 2015-02-10 00:05:41

0

你不需要tokenize()得到這個輸出:

of right hool herte & in oure best entent 

身份與模板變換一起壓制note會爲你做它:

<?xml version="1.0" encoding="utf-8"?> 
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:output method="text"/> 

    <xsl:template match="@*|node()"> 
    <xsl:copy> 
     <xsl:apply-templates select="@*|node()"/> 
    </xsl:copy> 
    </xsl:template> 

    <xsl:template match="note"/> 

</xsl:stylesheet> 

如果你想讓它用逗號分隔,可以將上述文本輸出捕獲到一個變量中,然後像上面提到的那樣應用tokenize

<?xml version="1.0" encoding="utf-8"?> 
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:output method="text"/> 

    <xsl:variable name="result"> 
    <xsl:apply-templates/> 
    </xsl:variable> 

    <xsl:template match="@*|node()"> 
    <xsl:copy> 
     <xsl:apply-templates select="@*|node()"/> 
    </xsl:copy> 
    </xsl:template> 

    <xsl:template match="note"/> 

    <xsl:template match="/"> 
    <xsl:value-of select="string-join(tokenize(normalize-space($result), ' '), ',')"/> 
    </xsl:template> 

</xsl:stylesheet> 

以上XSLT,給你的輸入XML,將產生以下文字:

of,right,hool,herte,&,in,oure,best,entent