Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
XML
data.xmlanalysis
mappoint.webservice
msf
msxml-webrelease
netmyservices.sdk
passport.sdk
soap
soapsdk
uddi.general
uddi.programming
uddi.specification
xml
xmlsqlwebrelease
xsl
  
 
date: Thu, 20 Mar 2008 20:33:25 -0000,    group: microsoft.public.xsl        back       


Parsing Augmented XHTML to XHTML using XSL   
I am wanting to parse an augmented XHTML with footnote elements 
<footnote>footnote</footnote> and <footnotes/> to XHTML using XSLT.

Before implementing footnotes I am having problems with the namespaces.

Given footnote.xsl :-

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:xhtml="http://www.w3.org/1999/xhtml">
        <xsl:output method="html" encoding="UTF-8"/>
        <xsl:template match="/xhtml:html">
          <html>
              <xsl:copy-of select="xhtml:head"/>
              <xsl:copy-of select="xhtml:body"/>
          </html>
        </xsl:template>
    </xsl:stylesheet>

And test.html :-

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
      <meta http-equiv="content-type" content="text/html; charset=utf-8" />
      <title>Footnote test</title>
    </head>
    <body>
        This is a test
    </body>
    </html>

I am getting :-

C:\Users\Aaron Gray\Documents>msxsl test.html footnotes.xsl

<html xmlns:xhtml="http://www.w3.org/1999/xhtml">
<head xmlns="http://www.w3.org/1999/xhtml">
  <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
  <title>Footnote test</title>
</head>
<body xmlns="http://www.w3.org/1999/xhtml">
    This is a test
</body>
</html>

I am obviously missing something simple, ie a default namespace definition, 
but cannot see how to.

Hope you can help.

Many thanks in advance,

Aaron
date: Thu, 20 Mar 2008 20:33:25 -0000   author:   Aaron Gray

Re: Parsing Augmented XHTML to XHTML using XSL   
"Aaron Gray"  wrote in message 
news:EC4B2A50-F2E8-4B76-9EC4-AA87E3B199F2@microsoft.com...
>I am wanting to parse an augmented XHTML with footnote elements 
><footnote>footnote</footnote> and <footnotes/> to XHTML using XSLT.
>
> Before implementing footnotes I am having problems with the namespaces.
>
> Given footnote.xsl :-
>
>    <?xml version="1.0" encoding="UTF-8"?>
>    <xsl:stylesheet version="1.0" 
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>                xmlns:xhtml="http://www.w3.org/1999/xhtml">
>        <xsl:output method="html" encoding="UTF-8"/>
>        <xsl:template match="/xhtml:html">
>          <html>
>              <xsl:copy-of select="xhtml:head"/>
>              <xsl:copy-of select="xhtml:body"/>
>          </html>
>        </xsl:template>
>    </xsl:stylesheet>
>
> And test.html :-
>
>    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
>    <html xmlns="http://www.w3.org/1999/xhtml">
>    <head>
>      <meta http-equiv="content-type" content="text/html; charset=utf-8" />
>      <title>Footnote test</title>
>    </head>
>    <body>
>        This is a test
>    </body>
>    </html>
>
> I am getting :-
>
> C:\Users\Aaron Gray\Documents>msxsl test.html footnotes.xsl
>
> <html xmlns:xhtml="http://www.w3.org/1999/xhtml">
> <head xmlns="http://www.w3.org/1999/xhtml">
>  <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
>  <title>Footnote test</title>
> </head>
> <body xmlns="http://www.w3.org/1999/xhtml">
>    This is a test
> </body>
> </html>
>
> I am obviously missing something simple, ie a default namespace 
> definition, but cannot see how to.


Okay very obvious !


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns="http://www.w3.org/TR/xhtml1/strict">
<xsl:output method="html" encoding="UTF-8"/>
<xsl:template match="/">
<html>
  <head>
    <xsl:copy-of select="/html/head"/>
  </head>
  <body>
    <xsl:copy-of select="/html/body"/>
  </body>
</html>
</xsl:template>
</xsl:stylesheet>

But reading from the input XHTML does not seem to work now :(

I tried adding an xmlns:xhtml namespace but that did not want to work 
either.

Aaron
date: Thu, 20 Mar 2008 23:51:21 -0000   author:   Aaron Gray

Re: Parsing Augmented XHTML to XHTML using XSL   
Aaron Gray wrote:

> <xsl:stylesheet version="1.0"
>                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>                xmlns="http://www.w3.org/TR/xhtml1/strict">
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
That is not an XHTML namespace, the namespace for XHTML 1 is 
http://www.w3.org/1999/xhtml.

> <xsl:output method="html" encoding="UTF-8"/>
> <xsl:template match="/">
> <html>
>  <head>
>    <xsl:copy-of select="/html/head"/>
>  </head>
>  <body>
>    <xsl:copy-of select="/html/body"/>
>  </body>
> </html>
> </xsl:template>
> </xsl:stylesheet>
> 
> But reading from the input XHTML does not seem to work now :(
> 
> I tried adding an xmlns:xhtml namespace but that did not want to work 
> either.

You will have to decide what the output of the stylesheet should be, 
whether you want HTML 4 with elements being in no namespace or whether 
you want XHTML with elements being in the namespace 
http://www.w3.org/1999/xhtml.
If the input is really XHTML (meaning elements in the XHTML namespace) 
and you want HTML 4 output then you can't use xsl:copy or xsl:copy-of as 
you then copy the elements including their namespace. Instead you need 
to strip the namespace e.g.
   <xsl:stylesheet
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      version="1.0"
      xmlns:xhtml="http://www.w3.org/1999/xhtml"
      exclude-result-prefixes="xhtml">

      <xsl:template match="xhtml:*">
        <xsl:element name="{local-name()}">
          <xsl:apply-templates select="@* | node()"/>
        </xsl:element>
      </xsl:template>




-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/
date: Fri, 21 Mar 2008 13:11:20 +0100   author:   Martin Honnen

Re: Parsing Augmented XHTML to XHTML using XSL   
"Martin Honnen"  wrote in message 
news:%23I8Lvy0iIHA.3780@TK2MSFTNGP06.phx.gbl...
> Aaron Gray wrote:
>
>> <xsl:stylesheet version="1.0"
>>                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>>                xmlns="http://www.w3.org/TR/xhtml1/strict">
>                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> That is not an XHTML namespace, the namespace for XHTML 1 is 
> http://www.w3.org/1999/xhtml.

Thanks I realized that later.

> You will have to decide what the output of the stylesheet should be, 
> whether you want HTML 4 with elements being in no namespace or whether you 
> want XHTML with elements being in the namespace 
> http://www.w3.org/1999/xhtml.
> If the input is really XHTML (meaning elements in the XHTML namespace) and 
> you want HTML 4 output then you can't use xsl:copy or xsl:copy-of as you 
> then copy the elements including their namespace. Instead you need to 
> strip the namespace e.g.

As the subject says I want XHTML to XHTML conversion :)

>   <xsl:stylesheet
>      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>      version="1.0"
>      xmlns:xhtml="http://www.w3.org/1999/xhtml"
>      exclude-result-prefixes="xhtml">
>
>      <xsl:template match="xhtml:*">
>        <xsl:element name="{local-name()}">
>          <xsl:apply-templates select="@* | node()"/>
>        </xsl:element>
>      </xsl:template>

Adding an output element converting output to UTF-8 :-

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      version="1.0"
      xmlns:xhtml="http://www.w3.org/1999/xhtml"
      exclude-result-prefixes="xhtml">

    <xsl:output method="html" encoding="UTF-8"/>
    <xsl:template match="xhtml:*">
        <xsl:element name="{local-name()}">
            <xsl:apply-templates select="@* | node()"/>
        </xsl:element>
    </xsl:template>
</xsl:stylesheet>

This produces malformed output.

<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">

  <meta>content-typetext/html; charset=utf-8
  <title>Footnote test</title>
</head>
<body>
    This is a test
</body>
</html>

Given :-

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
      <meta http-equiv="content-type" content="text/html; charset=utf-8" />
      <title>Footnote test</title>
    </head>
    <body>
        This is a test
    </body>
    </html>

Thanks,

Aaron
date: Fri, 21 Mar 2008 18:49:14 -0000   author:   Aaron Gray

Re: Parsing Augmented XHTML to XHTML using XSL   
The following seems to work for a start ...

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      version="1.0"
      xmlns="http://www.w3.org/1999/xhtml"
      >

    <xsl:output method="xml" encoding="UTF-8" indent="yes"/>

    <xsl:template match="/">
      <html>
        <xsl:apply-templates select="*"/>
      </html>
    </xsl:template>

    <xsl:template match="*">
        <xsl:copy-of select="*"/>
    </xsl:template>
</xsl:stylesheet>

Thanks,

Aaron
date: Fri, 21 Mar 2008 19:19:24 -0000   author:   Aaron Gray

Re: Parsing Augmented XHTML to XHTML using XSL - problems matching head and body   
I cannot seem to get head and body to match :-

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      version="1.0"
      xmlns="http://www.w3.org/1999/xhtml"
      >

    <xsl:output method="xml" encoding="UTF-8" indent="yes"/>

    <xsl:template match="/">
      <html>
        <xsl:apply-templates select="." mode="html"/>
      </html>
    </xsl:template>

    <xsl:template match="head" mode="html">
        head
        <xsl:copy-of select="*"/>
    </xsl:template>

    <xsl:template match="body" mode="html">
        body
        <xsl:copy-of select="*"/>
    </xsl:template>

</xsl:stylesheet>

Help,

Aaron
date: Fri, 21 Mar 2008 20:14:25 -0000   author:   Aaron Gray

Re: Parsing Augmented XHTML to XHTML using XSL   
I was given a solution by Jesper Tverskov on the XSL mailing list :-

        http://www.xmlplease.com/xhtmlxhtml

It does the job nicely.

Aaron
date: Sat, 22 Mar 2008 21:03:10 -0000   author:   Aaron Gray

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us