Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 311
  • Last Modified:

DOCTYPE Tag in Input File messing up may <xsl:template match> tags

I have some well formed xhtml input files that will be processed by an XSLT stylesheet.  In the XSLT stylesheet I have a template match tag to process the <a> tags in my xhtml input files.  The <xsl:template match="a"> tags in my XSLT stylesheet are not executed when an <a> tag in encountered in my xhtml input files when the input file contains the following DOCTYPE tag as it's first line:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">.

I need this DOCTYPE tag in some of my xhtml input files however.  In the input files that do not have the DOCTYPE tag the XSLT's <xsl:template match="a"> is executed when it encounters an <a> tag in those xhtml input files.  How can I get the template tag in the stylesheet to work with the xhtml input files that contain the DOCTYPE tag?


The Template match tag in my XSLT stylesheet:

<xsl:template match="a">
   <xsl:element name="Link">
      <xsl:attribute name="xlink:type">simple</xsl:attribute>
      <xsl:attribute name="xlink:href"><xsl:value-of select="@href" /></xsl:attribute>
      <xsl:attribute name="xlink:show">new</xsl:attribute>
      <xsl:attribute name="xlink:actuate">onRequest</xsl:attribute>
      <xsl:apply-templates/>
   </xsl:element>

Please help,
Dave
0
gdkinney_2
Asked:
gdkinney_2
  • 3
1 Solution
 
Geert BormansCommented:
Hi Dave,

can you check the following for me?
do the html tag have a namespace declaration?
They will likely have one when there is a DOCTYPE
and they will likely not have one when there isn't a DOCTYPE
That will be the cause of the problem, not the DOCTYPE


Cheers!
0
 
Geert BormansCommented:
Dave,

if you have this
<html xmlns="-//W3C//DTD XHTML 1.0 Transitional//EN">...

here is what you need to do
have the following namespace-declaration in your stylesheet element
xmlns:htm="-//W3C//DTD XHTML 1.0 Transitional//EN"
also have an exclude-result-prefixes="htm" in the stylesheet element as well

your html is in the xhtml namespace
and your result tree already occupies the default (null) namespace.
by prefixing the xhtml namespace (and making sure the namespace node is not copied to the result tree)
you get access to the xhtml elements

make sure you prefix all elements in all XPath expressions
and access the elements like this
<xsl:template match="htm:a">
   <xsl:element name="Link">
      <xsl:attribute name="xlink:type">simple</xsl:attribute>
      <xsl:attribute name="xlink:href"><xsl:value-of select="@href" /></xsl:attribute>
      <xsl:attribute name="xlink:show">new</xsl:attribute>
      <xsl:attribute name="xlink:actuate">onRequest</xsl:attribute>
      <xsl:apply-templates/>
   </xsl:element>

cheers

0
 
gdkinney_2Author Commented:
Gertone,
   The first 2 tags in my input xhtml file are as follows:

<!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" xml:lang="en" dir="ltr"
lang="en">

Dave
0
 
Geert BormansCommented:
so, as I said, the DOCTYPE is not the problem,
the namespace declaration in the html tag is

make sure you add in your stylesheet element:

<xsl:stylesheet xmlns:htm="http://www.w3.org/1999/xhtml" exclude-result-prefixes="htm" ....

and prefix every html element from the source tree with htm: in every XPath

eg. <xsl:value-of select="h1"/> should become <xsl:value-of select="htm:h1"/>
or use local-name() a lot instead of name()

cheers

Geert
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now