Question

I am trying to transform some HTML files to my own XML-format via XSL.

For this purpose I use HTML Tidy to clean up the input files, then transform them to xhtml with html2xhtml and then use a xsl script with msxsl to transform the xhtml files to my own format.

However, the last step is failing with not a error message at all (it is a semantical fail; not a technical ;-)): My output file just contains empty tags.

I had a problem like this before and removed the xmlns attribute from the html tag, what causes nearly all of the online transformers to work with my files correctly. MSXSL now writes the following error message: "Use of default namespace declaration attribute in DTD not supported".

Find the files I use here: http://pastie.org/5483087

Thank you in advance!

Was it helpful?

Solution

Well that is the FAQ with XSLT and XPath 1.0, the elements in your input XHTML document are in a namespace and your XSLT does not take that into account. You need to change it to e.g.

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xhtml="http://www.w3.org/1999/xhtml"
exclude-result-prefixes="xhtml">
<xsl:template match="/">

  <stellenausschreibung>
    <hochschule><xsl:value-of select="//xhtml:div[@id='contentText']/xhtml:img/@alt" /></hochschule>
    <anbieter><xsl:value-of select="//xhtml:p[@id='ad_employer']" /></anbieter>
    <typ><xsl:value-of select="//xhtml:h1" /></typ>
    <bewerbungsschluss><xsl:value-of select="//xhtml:span[@id='ad_bewerbungsschluss']" /></bewerbungsschluss>
    <erscheinungsdatum><xsl:value-of select="//xhtml:span[@class='job_published_at']" /></erscheinungsdatum>

    <inhalt><xsl:value-of select="//xhtml:p[@id='ad_job']" /></inhalt>
  </stellenausschreibung>

</xsl:template>
</xsl:stylesheet>

The prefix (in my example xhtml) for the XHTML namespace used in the stylesheet can of course be freely chosen but it is necessary to use one as with XSLT/XPath 1.0 a path of e.g. //p always selects p elements in no namespace.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top