views:

80

answers:

2

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"&gt;
<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 to get list of Links, but I get whole page on output. What's wrong? How can I get it works?

+3  A: 

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>
nullptr
+1  A: 

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.

Carl Smotricz