Why doesn't this XSLT work?

Discussion in 'XML' started by Sebastien B., Dec 19, 2004.

  1. Sebastien B.

    Sebastien B. Guest

    I've trying to modify an XHTML document, copying everything but replacing
    the divs with alternate content (simplified stylesheet below), but they
    never get replaced

    According to the O'Reilly book I have and the 5-6 examples I've seen, this
    is correct; so what am I missing?

    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:eek:utput method="html" indent="yes" />

    <xsl:template match="div">
    <div style="border: 1px solid red">
    blah blah blah
    </div>
    </xsl:template>

    <xsl:template match="*">
    <xsl:copy>
    <xsl:copy-of select="@*" />
    <xsl:apply-templates/>
    </xsl:copy>
    </xsl:template>

    <xsl:template match="comment()|processing-instruction()">
    <xsl:copy />
    </xsl:template>

    </xsl:stylesheet>
    Sebastien B., Dec 19, 2004
    #1
    1. Advertising

  2. Sebastien B.

    Joris Gillis Guest

    > I've trying to modify an XHTML document, copying everything but replacing
    > the divs with alternate content (simplified stylesheet below), but they
    > never get replaced
    >
    > According to the O'Reilly book I have and the 5-6 examples I've seen, this
    > is correct; so what am I missing?
    >

    Hi,

    That's a very frustrating bug.
    The problem is the default namespace in your XHTML. (probably "http://www.w3.org/1999/xhtml")
    You have to include that namspace in the xsl and add a prefix to the elements that should be matched.
    For example:

    <?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:eek:utput method="xml" indent="yes"/>

    <xsl:template match="xhtml:div">
    <div style="border: 1px solid red">
    blah blah blah
    </div>
    </xsl:template>

    <xsl:template match="*">
    <xsl:copy>
    <xsl:copy-of select="@*" />
    <xsl:apply-templates/>
    </xsl:copy>
    </xsl:template>

    <xsl:template match="comment()|processing-instruction()">
    <xsl:copy />
    </xsl:template>

    </xsl:stylesheet>


    regards,

    --
    Joris Gillis (http://www.ticalc.org/cgi-bin/acct-view.cgi?userid=38041)
    Gaudiam omnibus traderatW3C , nec vana fides
    Joris Gillis, Dec 19, 2004
    #2
    1. Advertising

  3. Sebastien B.

    Joris Gillis Guest

    > <?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">


    That should be:
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml" xmlns:xhtml="http://www.w3.org/1999/xhtml" exclude-result-prefixes="xhtml">

    But this approach is getting bloated...
    Maybe you'd better await a wiser answer from Martin Honnen or David Carlisle

    --
    Joris Gillis (http://www.ticalc.org/cgi-bin/acct-view.cgi?userid=38041)
    Gaudiam omnibus traderat W3C , nec vana fides
    Joris Gillis, Dec 19, 2004
    #3
  4. Sebastien B.

    Sebastien B. Guest

    > Hi,
    >
    > That's a very frustrating bug.


    Now when you say that, do you mean a bug in my template, or a bug in the
    implementation (ie. would I be better off using a 2.x template instead)?
    Sebastien B., Dec 21, 2004
    #4
  5. Sebastien B.

    Joris Gillis Guest

    >> That's a very frustrating bug.
    >
    > Now when you say that, do you mean a bug in my template, or a bug in the
    > implementation


    No no, I just wanted to say it's frustrating for someone learning XSLT to suddenly come across a stylesheet that refuses to work because of a detail you're overlooking. I once spent 4 hours looking for the cause of a similar bug.

    > (ie. would I be better off using a 2.x template instead)?

    2.0 does not yet exist, so you can't use it. Besides the specific problem here (namespace issue) is quite fundamental, I don't think there will be major changes in XSLT2.0 concerning namespaces of the source document (I could be wrong though).

    regards,

    --
    Joris Gillis (http://www.ticalc.org/cgi-bin/acct-view.cgi?userid=38041)
    Deserta faciunt et fenestras appelant
    Joris Gillis, Dec 21, 2004
    #5
  6. "Joris Gillis" <> writes:

    > >> That's a very frustrating bug.

    > >
    > > Now when you say that, do you mean a bug in my template, or a bug in the
    > > implementation

    >
    > No no, I just wanted to say it's frustrating for someone learning XSLT
    > to suddenly come across a stylesheet that refuses to work because of a
    > detail you're overlooking. I once spent 4 hours looking for the cause
    > of a similar bug.
    >
    > > (ie. would I be better off using a 2.x template instead)?

    > 2.0 does not yet exist, so you can't use it.



    well it exists in working draft stage and there exist fairly complete
    implementations so you can use it (although being a draft it may be
    advisable not to use for production code yet) see saxon 8.x

    > Besides the specific problem here (namespace issue) is quite
    > fundamental, I don't think there will be major changes in XSLT2.0
    > concerning namespaces of the source document (I could be wrong
    > though).


    The main change in this area is that you can set a default namespace for
    element names in XPath expressions, so that you don't have to explictly
    prefix element names in XPath and XSLT patterns in order to refer to
    elements in a namespace.


    >
    > regards,
    >
    > --
    > Joris Gillis (http://www.ticalc.org/cgi-bin/acct-view.cgi?userid=38041)
    > Deserta faciunt et fenestras appelant



    David
    David Carlisle, Dec 22, 2004
    #6
  7. Sebastien B.

    Joris Gillis Guest

    >> > (ie. would I be better off using a 2.x template instead)?
    >> 2.0 does not yet exist, so you can't use it.

    >
    > well it exists in working draft stage and there exist fairly complete
    > implementations so you can use it (although being a draft it may be
    > advisable not to use for production code yet) see saxon 8.x
    >


    Yes, but theoretically, it can always be recalled and redesigned from scratch.

    >> Besides the specific problem here (namespace issue) is quite
    >> fundamental, I don't think there will be major changes in XSLT2.0
    >> concerning namespaces of the source document (I could be wrong
    >> though).

    >
    > The main change in this area is that you can set a default namespace for
    > element names in XPath expressions, so that you don't have to explictly
    > prefix element names in XPath and XSLT patterns in order to refer to
    > elements in a namespace.


    That's indeed quite interesting...
    Up until now, I never took a good look at XSLT2.0 , maybe I should start learning it while it is still in working draft stage. Do you have any idea about the timescale (when will the recommendation be finished?) or is that unpredictable?

    regards,
    --
    Joris Gillis (http://www.ticalc.org/cgi-bin/acct-view.cgi?userid=38041)
    "Quot capita, tot sententiae"
    Joris Gillis, Dec 22, 2004
    #7

  8. > Do you have any idea about the timescale (when will the recommendation
    > be finished?) or is that unpredictable?


    Late next year they reckon, XSLT has been very stable with very few
    changes between drafts, mainly XSLT2 has been playing catch up while
    Xquery got developed (as they both depend on XPath2, all three need to
    be finalised together). Xquery has now been through "last call" so it is
    also getting fairly stable. I don't expect any large changes now, the
    time is required to get through teh W3C review processes, and show
    interoperable implementations, etc.


    Note, I'm not on the working group, this is all just unreliable gossip:)

    David
    David Carlisle, Dec 22, 2004
    #8
  9. Sebastien B.

    Joris Gillis Guest

    >> Do you have any idea about the timescale (when will the recommendation
    >> be finished?) or is that unpredictable?

    >
    > Late next year they reckon, XSLT has been very stable with very few
    > changes between drafts, mainly XSLT2 has been playing catch up while
    > Xquery got developed (as they both depend on XPath2, all three need to
    > be finalised together). Xquery has now been through "last call" so it is
    > also getting fairly stable. I don't expect any large changes now, the
    > time is required to get through the W3C review processes, and show
    > interoperable implementations, etc.


    That looks very promising. Patience will finally be rewarded...

    > Note, I'm not on the working group, this is all just unreliable gossip:)

    okay;)



    --
    Joris Gillis (http://www.ticalc.org/cgi-bin/acct-view.cgi?userid=38041)
    "Quot capita, tot sententiae"
    Joris Gillis, Dec 22, 2004
    #9
    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. David Prowak

    Why oh why doesn't my data view work?

    David Prowak, Jan 30, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    728
    Alvin Bruney [MVP]
    Jan 30, 2004
  2. Mr. SweatyFinger

    why why why why why

    Mr. SweatyFinger, Nov 28, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    874
    Mark Rae
    Dec 21, 2006
  3. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,803
    Smokey Grindel
    Dec 2, 2006
  4. Sara
    Replies:
    6
    Views:
    253
    John W. Krahn
    Apr 12, 2004
  5. PerlFAQ Server
    Replies:
    0
    Views:
    255
    PerlFAQ Server
    Apr 26, 2011
Loading...

Share This Page