开发者

Using XSLT as xhtml link extractor

I'm starting using XSLT and write this scipt:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" encoding="utf-8" />
<xsl:template match="span[@class='thumb']" >
    Link: <xsl:value-of select="$base" /><xsl:value-of select="a/@href" />
</xsl:template>

<xsl:template match="/">
    Base href: <xsl:value-of select="$base" />
    <xsl:apply-templates/>
</xsl:template>

</xsl:stylesheet>

And using this command:

xsltproc --html --param base "'http://example.com'" lista.xslt test.html

I need 开发者_Go百科to get list of Links, but I get whole page on output. What's wrong? How can I get it works?


There are some default templates which are unseen here. The really easy way to resolve it is to just explicitly limit to the span elements you're matching as below. Otherwise, you can override the default templates.

<xsl:template match="/">
  Base href: <xsl:value-of select="$base" />
  <xsl:apply-templates select="//span[@class='thumb']" />
</xsl:template>


There's a default template that matches essentially everything if you let it. Your 4th last line calls that template.

That's part of the problem. The rest can probably be taking care of by matching just the stuff you're looking for, directly in the top-level template.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜