XSLT Debugger stalling on initial <!DOCTYPE> tag

Here should go questions about transforming XML with XSLT and FOP.
LMCGIB10
Posts: 6
Joined: Wed Feb 15, 2012 5:45 pm

XSLT Debugger stalling on initial <!DOCTYPE> tag

Post by LMCGIB10 »

Hi Guys,

I'm (trying to ) write some XSLT to transform XHTML to XML, a snippet of the source XHTML is below.

Code: Select all


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Building Standards Domestic Handbook - General</title>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta name="keywords" content="Building Standards Scotland, Technical Handbooks, Domestic, 2010" />
When stepping through the XSLT using the XSLT Debugger the trace indicates a red dot (error?) when it encounters the very first <DOCTYPE html...
blah blah blah> (line 1 in the XHTML)

The XSLT I've written to markup the "html/head/title" is the following:

Code: Select all


<?xml version="1.0" encoding="UTF-8"?>
<!-- sts_transform.xsl
This xsl document is the main xslt used to transform Scottish
Technical Standards domestic, into an XML representation
which comply with the crown legisaltion markup language
xsd's.-->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.legislation.gov.uk/namespaces/legislation"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xml:base="http://www.legislation.gov.uk/id/asp/2003/8"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:dct="http://purl.org/dc/terms/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:ukm="http://www.legislation.gov.uk/namespaces/metadata">
<xsl:output method="xml"/>
<xsl:output indent="yes"/>
<xsl:strip-space elements="body"/>

<xsl:template match="/">
<Legislation>
<ukm:Metadata>
<xsl:apply-templates select="html/head"/>
</ukm:Metadata>
</Legislation>
</xsl:template>

<xsl:template match ="title">
<dc:title>
<xsl:value-of select="."/>
</dc:title>
</xsl:template>
</xsl:stylesheet>


The output I'm getting is

Code: Select all


<?xml version="1.0" encoding="utf-8"?>
<Legislation xmlns="http://www.legislation.gov.uk/namespaces/legislation" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dct="http://purl.org/dc/terms/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:ukm="http://www.legislation.gov.uk/namespaces/metadata">
<ukm:Metadata/>
</Legislation>
So I can only assume there is a problem with my XSLT, but can someone poin out where please?

Thanks in advance for any help.

Lewis
adrian
Posts: 2879
Joined: Tue May 17, 2005 4:01 pm

Re: XSLT Debugger stalling on initial <!DOCTYPE> tag

Post by adrian »

Hello,

It's a namespace problem.
In the XHTML the default namespace is: http://www.w3.org/1999/xhtml
In your stylesheet the default namespace is: http://www.legislation.gov.uk/namespaces/legislation
You need to map the XHTML namespace to a prefix and use that prefix in the XPaths (select/match) from the stylesheet.

Add to the root:
xmlns:html="http://www.w3.org/1999/xhtml"

Change:
<xsl:apply-templates select="html/head"/>
to:
<xsl:apply-templates select="html:html/html:head"/>

and

<xsl:template match="title">
to
<xsl:template match="html:title">

Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Post Reply