<xsl:apply-templates> effect on DOM object type?

Discussion in 'XML' started by Joseph Kesselman, Apr 12, 2007.

  1. XSLT is namespace-aware. Your stylesheet copies a <span> element with no
    namespace into the output document, which means it won't be recognized
    as being an XHTML span element.

    Change your code to:

    <xsl:template match="x">
    <span xmlns="http://www.w3.org/1999/xhtml">
    <svg xmlns="http://www.w3.org/2000/svg" />
    </span>
    </xsl:template>

    --
    Joe Kesselman / Beware the fury of a patient man. -- John Dryden
    Joseph Kesselman, Apr 12, 2007
    #1
    1. Advertising

  2. I am using Firefox 2.0.0.3 on MSWindows.
    I have an XML file http://emle.sourceforge.net/emle020000/testb.xml
    which invokes an XSLT file http://emle.sourceforge.net/emle020000/testb.xsl

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <?xml-stylesheet href="testb.xsl" type="text/xsl"?>
    <z xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <x/>
    </z>


    <?xml version="1.0" encoding="ISO-8859-1"?>
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:eek:utput
    method="xml"
    encoding="iso-8859-1"
    indent="yes"
    doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
    doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
    />

    <xsl:template match="/z">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <script>
    .... DEBUG CODE DELETED. ...
    </head>
    <body onload="init();">
    <div>
    <xsl:apply-templates select="x" />
    </div>
    </body>
    </html>
    </xsl:template>

    <xsl:template match="x">
    <span>
    <svg xmlns="http://www.w3.org/2000/svg" />
    </span>
    </xsl:template>

    </xsl:stylesheet>


    The result of the transform is:
    <!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
    xmlns="http://www.w3.org/1999/xhtml"><script type="text/javascript">
    function init() { lu = function luf(){return
    'http://www.w3.org/1999/xhtml';}; var span = document.evaluate("//span",
    document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null)
    ..singleNodeValue; var div = document.evaluate("//xhtml:div", document,
    lu, XPathResult.FIRST_ORDERED_NODE_TYPE, null) .singleNodeValue;
    alert("span:" + span + " div:" + div); return; } </script></head><body
    xmlns="http://www.w3.org/1999/xhtml" onload="init();"> <div> <span> <svg
    xmlns="http://www.w3.org/2000/svg"/> </span> </div></body></html>The alert
    displays span as an Element object and the div as an HTMLDivElement.
    What is it about the <xsl:template match="x"> that has this effect?

    --
    C.W.Holeman II | -5 | http://JulianLocals.com/cwhii
    To only a fraction of the human race does God give the privilege of
    earning one's bread doing what one would have gladly pursued free, for
    passion. I am very thankful. The Mythical Man-Month Epilogue/F.P.Brooks
    C.W.Holeman II, Apr 12, 2007
    #2
    1. Advertising

  3. Wrapped lines fixed.

    I am using Firefox 2.0.0.3 on MSWindows.
    I have an XML file http://emle.sourceforge.net/emle020000/testb.xml
    which invokes an XSLT file http://emle.sourceforge.net/emle020000/testb.xsl

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <?xml-stylesheet href="testb.xsl" type="text/xsl"?>
    <z xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <x/>
    </z>


    <?xml version="1.0" encoding="ISO-8859-1"?>
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:eek:utput
    method="xml"
    encoding="iso-8859-1"
    indent="yes"
    doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
    doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
    />

    <xsl:template match="/z">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <script>
    .... DEBUG CODE DELETED. ...
    </head>
    <body onload="init();">
    <div>
    <xsl:apply-templates select="x" />
    </div>
    </body>
    </html>
    </xsl:template>

    <xsl:template match="x">
    <span>
    <svg xmlns="http://www.w3.org/2000/svg" />
    </span>
    </xsl:template>

    </xsl:stylesheet>


    The result of the transform is:

    <!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 xmlns="http://www.w3.org/1999/xhtml">
    <script type="text/javascript">
    function init() {
    lu = function luf(){return 'http://www.w3.org/1999/xhtml';};
    var span = document.evaluate("//span",
    document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null)
    .singleNodeValue;
    var div = document.evaluate("//xhtml:div",
    document, lu, XPathResult.FIRST_ORDERED_NODE_TYPE, null)
    .singleNodeValue;
    alert("span:" + span + " div:" + div);
    return;
    }
    </script>
    </head>
    <body xmlns="http://www.w3.org/1999/xhtml" onload="init();">
    <div>
    <span>
    <svg xmlns="http://www.w3.org/2000/svg"/>
    </span>
    </div>
    </body>
    </html>

    The alert displays span as an Element object and the div as an
    HTMLDivElement.
    What is it about the <xsl:template match="x"> that has this effect?

    --
    C.W.Holeman II | -5 | http://JulianLocals.com/cwhii
    To only a fraction of the human race does God give the privilege of
    earning one's bread doing what one would have gladly pursued free, for
    passion. I am very thankful. The Mythical Man-Month Epilogue/F.P.Brooks
    C.W.Holeman II, Apr 12, 2007
    #3
  4. C.W.Holeman II wrote:

    > <xsl:stylesheet version="1.0"
    > xmlns:xsl="http://www.w3.org/1999/XSL/Transform">


    Add
    xmlns="http://www.w3.org/1999/xhtml"
    to the xsl:stylesheet element, that way all your literal XHTML elements
    will be in the XHTML namespace. Otherwise in any template you write you
    will need to make sure that the XHTML default namespace declaration is
    set for XHTML elements.



    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Apr 12, 2007
    #4
  5. "Joseph Kesselman" <> wrote in message
    news:461e4471@kcnews01...
    > XSLT is namespace-aware. Your stylesheet copies a <span> element with no
    > namespace into the output document, which means it won't be recognized as
    > being an XHTML span element.
    >
    > Change your code to:
    >
    > <xsl:template match="x">
    > <span xmlns="http://www.w3.org/1999/xhtml">
    > <svg xmlns="http://www.w3.org/2000/svg" />
    > </span>
    > </xsl:template>


    "Martin Honnen" <> wrote in message
    news:461e5ddd$0$10182$-online.net...
    > C.W.Holeman II wrote:
    >
    >> <xsl:stylesheet version="1.0"
    >> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    >
    > Add
    > xmlns="http://www.w3.org/1999/xhtml"
    > to the xsl:stylesheet element, that way all your literal XHTML elements
    > will be in the XHTML namespace. Otherwise in any template you write you
    > will need to make sure that the XHTML default namespace declaration is set
    > for XHTML elements.


    That does it. Thanks again. Corrected and working version:

    http://emle.sourceforge.net/emle020000/testb2.xml
    http://emle.sourceforge.net/emle020000/testb2.xsl

    --
    C.W.Holeman II | -5 | http://JulianLocals.com/cwhii
    To only a fraction of the human race does God give the privilege of
    earning one's bread doing what one would have gladly pursued free, for
    passion. I am very thankful. The Mythical Man-Month Epilogue/F.P.Brooks
    C.W.Holeman II, Apr 12, 2007
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stefan Siegl
    Replies:
    1
    Views:
    958
    Marrow
    Jul 18, 2003
  2. Cyrille \cns\ Szymanski

    xsl apply-templates select=not(...)

    Cyrille \cns\ Szymanski, Nov 7, 2003, in forum: XML
    Replies:
    4
    Views:
    596
    Cyrille \cns\ Szymanski
    Nov 11, 2003
  3. Sparko
    Replies:
    0
    Views:
    407
    Sparko
    Jul 9, 2004
  4. Vijay singh
    Replies:
    1
    Views:
    433
    Martin Honnen
    Nov 4, 2004
  5. KJ
    Replies:
    7
    Views:
    572
    Andreas Kraftl
    May 29, 2005
Loading...

Share This Page