简体   繁体   English

XSL value-of返回不匹配

[英]XSL value-of returns no match

Alright I am trying to convert an XHTML document to RDF/XML (don't ask, it's an assignment) using XSLT where the information for the RDF file is located in meta tags in the XHTML document. 好的,我正在尝试使用XSLT将XHTML文档转换为RDF / XML(不要问,这是一项任务),其中RDF文件的信息位于XHTML文档的元标记中。 I have my first XPath query done to locate the value of the about attribute of <rdf:Description> . 我完成了第一个XPath查询,以找到<rdf:Description>about属性的值。 I tested the XPath query on a separate website where it returned the proper result. 我在单独的网站上测试了XPath查询,该查询返回了正确的结果。 However, when I try to incorporate it in my XSLT the result is an empty string. 但是,当我尝试将其合并到XSLT中时,结果是一个空字符串。

I'm just looking for a nudge in the right direction. 我只是在寻找正确方向的推动力。 I don't see where I'm wrong. 我看不到我错了。 Here's the example XHTML document. 这是示例XHTML文档。

<?xml version="1.0" encoding="ISO-8859-1" ?>
<?xml-stylesheet href="TN6_Q6.xsl" type="text/xsl" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <link rel="schema.DC" href="http://purl.org/dc/elements/1.1/" />
    <meta name="DC.title" content="le titre de mon document" />
    ...
    <title>...</title>
  </head>
  <body>
    ...
  </body>
</html>

That's the XSLT I have built so far. 那就是我到目前为止构建的XSLT。 I know it looks awful but again... that's the assignment. 我知道它看起来很糟糕,但是...又是任务。

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xhtml="http://www.w3.org/1999/xhtml">
<xsl:template match="*">
<html><body><pre>
&lt;?xml version="1.0" encoding="ISO-8859-1" ?&gt;
&lt;rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" &gt;
&lt;rdf:Description rdf:about="

  <!-- THIS LINE -->
  <xsl:value-of select="html/*[local-name()='head']/*[local-name()='link']/@href"/>"&gt;

&lt;/rdf:Description&gt;
&lt;/rdf:RDF&gt;
</pre></body></html>
</xsl:template>
</xsl:stylesheet>

You can test the XPath right here: http://www.xpathtester.com/saved/85785aab-0449-472e-a94f-77ee49d4e330 您可以在此处测试XPath: http : //www.xpathtester.com/saved/85785aab-0449-472e-a94f-77ee49d4e330

Your template matches "*" so the context node when that value-of is evaluated will be the root html element. 您的模板与"*"匹配,因此,在value-of时,上下文节点将为html根元素。 Therefore you only need to start the path from head : 因此,您只需要从head开始路径:

<xsl:value-of select="*[local-name()='head']/*[local-name()='link']/@href"/>

Or better than the local-name() trick would be to use the fact that you've declared the namespace in the <xsl:stylesheet> and use the corresponding qualified names in the path: local-name()技巧更好的是,使用以下事实:您已经在<xsl:stylesheet>声明了名称空间,并在路径中使用了相应的限定名称:

<xsl:value-of select="xhtml:head/xhtml:link/@href" />

You might also consider changing the template to be match="/" instead of match="*" , in which case the context would be the document root node rather than the html element, so you would need to add the html to the front of the path: 您可能还考虑将模板更改为match="/"而不是match="*" ,在这种情况下,上下文将是文档根节点,而不是html元素,因此您需要将html添加到最前面路径:

<xsl:value-of select="xhtml:html/xhtml:head/xhtml:link/@href" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM