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
gdkinney_2Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Geert BormansInformation ArchitectCommented:
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 BormansInformation ArchitectCommented:
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 BormansInformation ArchitectCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.