I'm having trouble converting XHMTL files to XML while using a xslt 2.0 stylesheet. I know the question was answered for XSLT 1.0 but it really doesn't work for XSLT 2.0!
Example XHTML file:
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="de" xml:lang="de" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="something" content="content"/>
(...)
</head>
<body onload="...">
(...)
</body>
</html>
Example Stylesheet:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xhtml="http://www.w3.org/1999/xhtml">
<xsl:template match="xhtml:html/xhtml:head">
<section role="example">
<xsl:attribute name="id" select="concat('something', meta[@name='something']/@content)"/>
(...)
</section>
</xsl:stylesheet>
I'm unable to call the nodes. I'm using oxygen XML editor (older version unfortunately but for all XML transformation it worked just fine) and I tried different processors (Saxon-EE 9.4.0.6,Saxon HE 9.4.0.6, Saxon-PE9.4.0.6.). I looked at this issue XHTML to XML XSLT conversion which makes reference to XSLT 2.0 and also tried to replace the namespace in the match with an asterisk, but the editor doesn't accept it.
After the precious comment from @MartinHonnen I changed the XSLT to:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.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="xhtml:html/xhtml:head">
<section role="example">
<xsl:attribute name="id" select="concat('something', xhtml:meta[@name='something']/@content)"/>
(...)
</section>
</xsl:stylesheet>
This small change did the trick. All kinds of meta information can now be extracted from XHTML. With the former stylesheet in the resulting XML there was just "something_" filled in as value for id-attribute, e.g. This is a short result example with the corrected stylesheet:
<?xml version="1.0" encoding="UTF-8"?>
<section role="example" id="something_content">
(...)
</section>
Thanks again!!!!
meta
path should bexhtml:meta
as well. – Martin Honnen