XSL transform trying to be smarter?

W

Wizfrog

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!
 
J

Joe Kesselman

Wizfrog said:
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.
 
W

Wizfrog

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

Joe Kesselman

Wizfrog said:
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.)
 
W

Wizfrog

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

Joe Kesselman

Wizfrog said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top