1

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

2 Answers 2

3

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>
Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.