2015-02-09 60 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