Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml 如何从文本中提取超链接_Xml_Xslt_Xslt 1.0 - Fatal编程技术网

Xml 如何从文本中提取超链接

Xml 如何从文本中提取超链接,xml,xslt,xslt-1.0,Xml,Xslt,Xslt 1.0,My xml具有以下元素: <output_citation>C. T. Pan, R. R. Nair, U. Bangert, Q. Ramasse, R. Jalil, R. Zan, C. R. Seabourne, and A. J. Scott. (2012). Nanoscale electron diffraction and plasmon spectroscopy of single- and few-layer boron nitride. <em>

My xml具有以下元素:

<output_citation>C. T. Pan, R. R. Nair, U. Bangert, Q. Ramasse, R. Jalil, R. Zan, C. R. Seabourne, and A. J. Scott. (2012). Nanoscale electron diffraction and plasmon spectroscopy of single- and few-layer boron nitride. <em>Physical Review B</em>, 85(4), 045440.  eScholarID:<a class="escholarid"
        href="http://www.blah.ac.uk/escholar/uk-ac-blah-scw:205189">205189</a> | DOI:<a class="doi" href="http://dx.doi.org/10.1103/PhysRevB.85.045440">10.1103/PhysRevB.85.045440</a></output_citation>
C.T.Pan、R.R.Nair、U.Bangert、Q.Ramasse、R.Jalil、R.Zan、C.R.Seabourne和A.J.Scott。(2012). 单层和多层氮化硼的纳米级电子衍射和等离子体激元光谱。身体检查B,85(4),045440。艾斯考拉德:|内政部:
使用XSLT1.0 我需要提取两个超链接,并显示为可点击的链接。 我已设法使用以下方法提取第一个:

<xsl:variable name="urlEscholarId" select="output_citation/a/@href"> </xsl:variable>
<xsl:variable name="labelEscholarId" select="substring-after($urlEscholarId,'scw:')">       </xsl:variable>
 <a>
<xsl:attribute name="href"> 
<xsl:value-of select="$urlEscholarId"/>
</xsl:attribute>
<xsl:value-of select="$labelDoiId"/>
</a>

这给了我:

<a href="http://www.blah.ac.uk/escholar/uk-ac-blah-scw:205189">205189</a>

我似乎无法提取第二个,以及如何输出除th eurls之外的上述文本


非常感谢

注意:这些解决方案展示了如何单独执行任务。这可能适用于现有XSLT样式表,也可能不适用于现有XSLT样式表。如果没有,您将不得不透露更多的代码

1输出HTML链接

也许根本不需要为每个循环或变量使用
(无论如何,它们在某种程度上违背了XSLT的功能性)。要查找这两个链接,只需编写一个模板来匹配
a
元素,创建一个新的
a
元素(或复制现有元素),然后复制
href
属性和原始
a
元素的文本内容

我假设
class
属性不应该出现在输出中

样式表

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

    <xsl:template match="a">
        <a>
            <xsl:copy-of select="@href|text()"/>
        </a>   
    </xsl:template>

    <xsl:template match="text()"/>

</xsl:transform>
<?xml version="1.0" encoding="utf-8"?>
<a href="http://www.blah.ac.uk/escholar/uk-ac-blah-scw:205189">205189</a>
<a href="http://dx.doi.org/10.1103/PhysRevB.85.045440">10.1103/PhysRevB.85.045440</a>
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="xml" omit-xml-declaration="yes" indent="yes" /> 

    <xsl:template match="a/text()"/>

</xsl:transform>
文本输出

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

    <xsl:template match="a">
        <a>
            <xsl:copy-of select="@href|text()"/>
        </a>   
    </xsl:template>

    <xsl:template match="text()"/>

</xsl:transform>
<?xml version="1.0" encoding="utf-8"?>
<a href="http://www.blah.ac.uk/escholar/uk-ac-blah-scw:205189">205189</a>
<a href="http://dx.doi.org/10.1103/PhysRevB.85.045440">10.1103/PhysRevB.85.045440</a>
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="xml" omit-xml-declaration="yes" indent="yes" /> 

    <xsl:template match="a/text()"/>

</xsl:transform>
潘宗棠、奈尔、班格特、拉马塞、贾利勒、赞恩、西伯恩和斯科特。(2012). 单层和多层氮化硼的纳米级电子衍射和等离子体激元光谱。身体检查B,85(4),045440。Escholand:| DOI:


在这种情况下,您能显示实际期望的输出吗?在这个例子中,看起来您可以只执行
。@TimC也许
属性不应该再出现在输出中了?