XSL transform trying to be smarter?

Discussion in 'XML' started by Wizfrog, Jul 24, 2007.

  1. Wizfrog

    Wizfrog Guest

    Hello,

    I am using XSL to transform a XML file into a HTML output.
    classic

    so, I have a tag calling an image with a local path as

    <img src="images/myimage.jpg"/>

    nothing really strange here...

    I am just surprised to see that the output includes the FULL path to
    the image.
    so, XSL first is able to figure out that my img tag is an html tag and
    put in the full path there.

    it makes for a HUGE src field, and since I am generating an output
    with several images for each field, and hundreds of fields, it's just
    slow.
    i am thinking that all this extra text in the HTML just makes it
    heavier to handle, and just wish to use the simpler local path.

    Why is XSL generating the full path like this? How do I get around
    this?



    other thing i found out is that it keeps inserting attributes like:

    xmlns:td="urn:schemas-microsoft-com:datatypes" all over the place in
    my <div>

    I tried to use <xsl:element name="div"> instead of just <div> but it
    didn't help.

    any idea?

    thanks for help!
    Wizfrog, Jul 24, 2007
    #1
    1. Advertising

  2. Wizfrog wrote:
    > I am just surprised to see that the output includes the FULL path to
    > the image.
    > so, XSL first is able to figure out that my img tag is an html tag and
    > put in the full path there.


    What are you viewing the output with? XSLT *shouldn't* be expanding
    relative paths to full paths. Of course other tools (such as the
    browser) may be doing so.

    > Why is XSL generating the full path like this? How do I get around
    > this?


    If you're sure it's happening in the XSLT processor, I think that
    processor's broken. Try another?


    > other thing i found out is that it keeps inserting attributes like:
    > xmlns:td="urn:schemas-microsoft-com:datatypes" all over the place in
    > my <div>


    XSLT will insert the appropriate namespace nodes whenever it copies an
    element from a namespaced context. Some XSLT processors are better than
    others at recognizing that a namespace declaration is already in scope
    and that new declarations don't have to be issued. You may be able to
    help the processor/serializer by making sure a declaration for this
    prefix appears near the root of the document, so it *is* already in scope.

    --
    () ASCII Ribbon Campaign | Joe Kesselman
    /\ Stamp out HTML e-mail! | System architexture and kinetic poetry
    Joe Kesselman, Jul 24, 2007
    #2
    1. Advertising

  3. Wizfrog

    Wizfrog Guest

    I'm printing the output in the browser into a TEXTAREA container. Note
    that I'm using local file here.

    I was doing this because as I dump the output in a div, the divs next
    to it get moved around, which does not happen if I just dump text. I
    thought the xsl output may be malformed, but it's fine, except for all
    the added junk.



    I'm not sure I am familiar enough with the namespace stuff.
    what is xmlns:dt about? it shows up in the IMG tag

    my 1st tag is already:
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/
    Transform" xmlns:dt="urn:schemas-microsoft-com:datatypes">

    so why would it need to show up again? should I try version="2.0" ?
    Wizfrog, Jul 24, 2007
    #3
  4. Joe Kesselman wrote:
    >> other thing i found out is that it keeps inserting attributes like:
    >> xmlns:td="urn:schemas-microsoft-com:datatypes" all over the place in
    >> my <div>


    I forgot to add that you may also want to play with the
    exclude-result-prefixes directive, if you're sure the prefix is not
    being used in your output tree (including in text content such as
    XPaths). See discussion at

    http://www.w3.org/TR/xslt#literal-result-element

    --
    () ASCII Ribbon Campaign | Joe Kesselman
    /\ Stamp out HTML e-mail! | System architexture and kinetic poetry
    Joe Kesselman, Jul 24, 2007
    #4
  5. Wizfrog wrote:
    > I'm not sure I am familiar enough with the namespace stuff.
    > what is xmlns:dt about?


    It binds the dt prefix to a particular namespace name.

    > <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/
    > Transform" xmlns:dt="urn:schemas-microsoft-com:datatypes">


    Which means this namespace is in scope for your entire stylesheet, so
    any element in the stylesheet inherits this declaration, so when you
    copy them to the result document the declaration comes with them.

    You can try outputting it earlier in your *RESULT* document and hope
    that inheritance keeps it from being repeated all over the place. Or, if
    you aren't using it, you can remove that declaration from the stylesheet
    and/or move it down to the place(s) where it is actually being used.

    > should I try version="2.0" ?


    2.0 doesn't change the behavior I cited. Either don't declare namespaces
    you aren't using, or try to make sure the output document declares them
    high up and hope your serializer's smart enough to take advantage of
    that, or explicitly suppress them (which works only if they aren't being
    referenced, and may cause trouble if there really was something that
    needed them -- basically, understand what you're doing before pulling
    the trigger), or live with the fact that XSLT will declare them when it
    notices that you haven't yet done so and they might be needed.
    (Redundant or distributed declarations are verbose but otherwise harmless.)




    >
    >



    --
    () ASCII Ribbon Campaign | Joe Kesselman
    /\ Stamp out HTML e-mail! | System architexture and kinetic poetry
    Joe Kesselman, Jul 24, 2007
    #5
  6. Wizfrog

    Wizfrog Guest

    got it. thanks

    what is dt for anyway? (I assume datatype) but what does it mean?

    I guess I used the header from somewhere else and didn't realize this
    was there.

    when should i have to use the dt namespace?
    Wizfrog, Jul 24, 2007
    #6
  7. Wizfrog wrote:
    > what is dt for anyway? (I assume datatype) but what does it mean?


    To find out what a namespace is used for, try to find out who defined
    the URI that represents it its name. (The prefix being bound is just a
    convenience, and is not itself meaningful; you can use any prefix as
    long as you're consistant about it.)

    Obviously, this one's defined by Microsoft. Websearch tells us that "The
    urn:schemas-microsoft-com:datatypes namespace defines a field used when
    defining properties for the Exchange store schema." If you aren't
    working with Exchange documents, you presumably don't need to declare it.

    Hence, the simplest way to fix your problem is probably to get rid of
    that namespace declaration.


    --
    () ASCII Ribbon Campaign | Joe Kesselman
    /\ Stamp out HTML e-mail! | System architexture and kinetic poetry
    Joe Kesselman, Jul 24, 2007
    #7
    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. annoyed tuna
    Replies:
    3
    Views:
    514
    David Carlisle
    Apr 20, 2005
  2. Replies:
    1
    Views:
    3,591
    A. Bolmarcich
    May 27, 2005
  3. Mark A. Gibbs

    smarter enums

    Mark A. Gibbs, Jul 12, 2004, in forum: C++
    Replies:
    27
    Views:
    2,704
    Mark A. Gibbs
    Jul 18, 2004
  4. Luc The Perverse

    Smarter than BigDecimal Class

    Luc The Perverse, Jul 17, 2006, in forum: Java
    Replies:
    6
    Views:
    1,781
    Patricia Shanahan
    Jul 17, 2006
  5. Michael T. Babcock

    Faster (smarter?) dictionary building

    Michael T. Babcock, Oct 30, 2003, in forum: Python
    Replies:
    2
    Views:
    332
    Bengt Richter
    Oct 30, 2003
Loading...

Share This Page